New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CORS sync sends OPTIONS request instead of POST #2542
Comments
Look up how CORS works -- this is the expected "preflight" request https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS#Preflighted_requests |
How can I avoid this reflight request? |
Only be sending a "simple request" as defined here: https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS#Simple_requests |
I tried this on server side to handle preflight calls:
but did not work, the browser does not send another request after the preflight... So you say that it is not possible with backbone.sync? |
Regardless, this isn't a Backbone issue, so I suggest asking on Stackoverflow or IRC. |
Can you explain me why this is not a backbone issue? |
Read through the source of Backbone.sync ( http://backbonejs.org/docs/backbone.html#section-134 ) and you'll see Backbone simply passes everything through to $.ajax. |
@Inf3rno try this one. header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: Content-Type');
header('Access-Control-Allow-Methods: POST'); This isn't Backbone issue at all. |
These are my original headers without php:
I think my server is well configured, but I tried out the headers you gave, and they did not work... Simple $.ajax calls work well, for example I load json files from the service with this:
I tried out this with any request method, and they responded well... The collection.fetch() works well too, I have problems only with the model.save() ... I tried it this way, maybe I'm doing something wrong:
I got the attributes and "error" in console. I'll check what kind of error is.. |
You were right, thanks! I added to server config the allow content-type, and it works now. Firebug is not the best, the Chrome console printed that the content-type is not allowed... |
Many tanks! :D |
header('Access-Control-Allow-Headers: Authorization, Content-Type'); Ah, it seems you solved the issue while I'm writing this. |
Ye, thanks anyway, you helped a lot! |
@Inf3rno Thanks so much for the comment about Chrome giving better error messages than Firebug! That helped us solve the problem. |
You're welcome! :-) |
Can someone please help on this issue? http://stackoverflow.com/questions/32725249/cors-filter-issue-for-authentrypoint |
In case anyone else is having this problem I had to add "x-http-method-override" to my list of Access-Control-Allow-Methods which is used when you set Backbone.emulateHTTP = true |
I'm trying to use the model.save() with a rest service on another subdomain. I got the following request headers which are far from my expectations:
How to fix this?
Ofc. my REST server responds 404 not found for an OPTIONS call...
To avoid unwanted questions: the server is ok, it handles REST calls and CORS calls well, tested with $.ajax and a REST interface tester application too.
The text was updated successfully, but these errors were encountered: