CORS is enabled on the backend. The jQuery underpinnings knows when it's make a cross-origin request and modifies it accordingly. The problem is the server, in this case, api.github.com
does not allow CORS requests.
The server would have to respond with (at minumum):
Access-Control-Allow-Origin: * (or the host in which your page is being served)
Since you likely do not own github, you'll have to either write a server-side proxy OR see if github can provide you with a JSONP call (which jQuery is happy to make for you as well).
MDN Documentation on Access-Control
EDIT
That being said, if you need to modify a request made by jQuery through backbone, there is no need to override the sync
method. Use jQuery's $.ajaxSetup
method to add any additional headers, set types, etc. Just make sure you run the $.ajaxSetup
method in the same context or closure as the .save()
, .fetch()
or .destroy()
is going to run or you won't get the work being performed in $.ajaxSetup
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…