Giter Site home page Giter Site logo

Comments (5)

akre54 avatar akre54 commented on May 29, 2024

It should be possible to override the headers object for those cases where you need to do something special. Let me know if that's not sufficient and we can reopen.

from backbone.fetch.

skinnyjames avatar skinnyjames commented on May 29, 2024

That's sort of the issue.
By overriding the headers to have a content type of "multipart/form-data," the server errors that the multipart boundary can't be found.

This seems to be an issue with how fetch itself works, based on other's experiences. The recommendation is to take the content-type out of the headers and let the browser generate it.

It's interesting because when I set the content-type to undefined I expect the defaults function to override it with 'application/json', but it comes through as a string e.g. - "content-type": "undefined". This might have to do with the way backbone's sync method works, but I still imagine that if the content-type header did come through as undefined, the defaults method would still override it.

Any ideas?

from backbone.fetch.

akre54 avatar akre54 commented on May 29, 2024

Unfortunately with the defaults function there's no nice way to remove a key, only override it. Maybe try with an empty string, or null?

It looks like fetch (or at least the fetch polyfill) has its own logic for when the content-type header is falsey. (I think this is the section in the spec, so should work in native implementations too).

from backbone.fetch.

skinnyjames avatar skinnyjames commented on May 29, 2024

Thanks for your help!

I tried the above. I don't quite understand why falsey values are being quoted/literalized when I inspect the request object from node - using the fetch polyfill it correctly sets the content-type/boundary, but chrome v55 doesn't. Fetch seems cool, but I think i'll just switch back to jQuery for now.

Thanks again

from backbone.fetch.

akre54 avatar akre54 commented on May 29, 2024

Sure, sorry to hear it.

Maybe as a last option, pass an headers object instead of trying to set the content-type directly? Should work. Otherwise if you can think of a good solution it might help the next person too.

from backbone.fetch.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.