Skip to content

Commit

Permalink
Issue jashkenas#154. Make options.data possible for creates and updat…
Browse files Browse the repository at this point in the history
…es with the default sync.
  • Loading branch information
jashkenas committed Dec 30, 2010
1 parent 1c30828 commit 4c1bdb4
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions backbone.js
Expand Up @@ -941,20 +941,24 @@
// it difficult to read the body of `PUT` requests.
Backbone.sync = function(method, model, options) {
var type = methodMap[method];
var modelJSON = (method === 'create' || method === 'update') ?
JSON.stringify(model.toJSON()) : null;

// Default JSON-request options.
var params = _.extend({
type: type,
contentType: 'application/json',
data: modelJSON,
dataType: 'json',
processData: false
}, options);

// Ensure that we have a URL.
params.url || (params.url = getUrl(model) || urlError());
if (!params.url) {
params.url = getUrl(model) || urlError();
}

// Ensure that we have the appropriate request data.
if (!params.data && model && (method == 'create' || method == 'update')) {
params.data = JSON.stringify(model.toJSON());
}

// For older servers, emulate JSON by encoding the request into an HTML-form.
if (Backbone.emulateJSON) {
Expand Down

0 comments on commit 4c1bdb4

Please sign in to comment.