Created
December 18, 2012 00:17
-
-
Save hokaccha/4323692 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Backbone.sync = function(method, model, options) { | |
var type = methodMap[method]; | |
// Default options, unless specified. | |
options || (options = {}); | |
// Default JSON-request options. | |
var params = {type: type, dataType: 'json'}; | |
// Ensure that we have a URL. | |
if (!options.url) { | |
params.url = getValue(model, 'url') || urlError(); | |
} | |
// Ensure that we have the appropriate request data. | |
if (!options.data && model && (method == 'create' || method == 'update')) { | |
params.data = model.toJSON(); | |
} | |
if (type === 'PUT' || type === 'DELETE') { | |
params.type = 'POST'; | |
params.beforeSend = function(xhr) { | |
xhr.setRequestHeader('X-HTTP-Method-Override', type); | |
}; | |
} | |
// Make the request, allowing the user to override any Ajax options. | |
return $.ajax(_.extend(params, options)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment