From 4c1bdb46a8aeba6a6fc9803614b074dbca2ec050 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Thu, 30 Dec 2010 12:28:55 -0500 Subject: [PATCH] Issue #154. Make options.data possible for creates and updates with the default sync. --- backbone.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/backbone.js b/backbone.js index cdbc86d0..356405b9 100644 --- a/backbone.js +++ b/backbone.js @@ -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) {