1

I have been able to implement a CORS response with a fetch().

However, when I look to save() a model using PUT have been unable to implement this. The response which comes back is

OPTIONS http://[external domain] 501 (Not Implemented)
XMLHttpRequest cannot load http://[external domain]. Origin http://127.0.0.1:8888 is not allowed by Access-Control-Allow-Origin.

Can anyone give me an example of how to change backbone sync to implement this? or is this even possible?

Joe
  • 1,841
  • 4
  • 27
  • 43
  • 1
    It looks like the server needs CORS support added not backbone. – abraham Feb 26 '12 at 17:39
  • Server has cors support hence the fetch request works – Joe Feb 26 '12 at 18:44
  • 1
    It is still a server issue. `501 Not Implemented: The server either does not recognise the request method, or it lacks the ability to fulfill the request.` - http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#5xx_Server_Error – abraham Feb 26 '12 at 18:56
  • What jquery version are you using? – ggozad Feb 26 '12 at 18:59
  • Also showing some headers would be useful. – ggozad Feb 26 '12 at 19:32
  • jquery 1.7.1. Re the server, I have added `Access-Control-Allow-Credentials: true` and `Access-Control-Allow-Methods: GET, POST, PUT` as well as `Access-Control-Allow-Origin: *` – Joe Feb 27 '12 at 10:11
  • If you inspect the response headers to the OPTIONS request those headers are present? – abraham Feb 28 '12 at 13:21
  • 1
    You can test it with `curl -v -X options http://127.0.0.1:8888/path` – abraham Feb 28 '12 at 13:25
  • @Joe, Please have a look at my answer to a related post on a similar issue. – Karthik Apr 06 '12 at 04:04

2 Answers2

3

When you do any action other than a GET using CORS you have to go through the pre-flight process as outlined in this question/answer: CORS - How do 'preflight' an httprequest? and also on this blog post: http://avalanche123.com/blog/2011/10/10/cross-domain-javascript-lessons-learned/

You have to make some extra steps beyond the easy GET CORS workflow.

Community
  • 1
  • 1
Darren Newton
  • 2,847
  • 1
  • 29
  • 31
0

Have a look at easyXDM. It provides a simple interface for enabling backwards compatible CORS. I don't have any sample for how to implement Backbone.sync, but it should be pretty straight forward.

Hope this helps!

thedersen
  • 243
  • 1
  • 5