mythz/jquip

JSON.stringify call in ajax() double encodes json from Backbone

statianzo opened this issue · 4 comments

Backbone's invocation of ajax() passes data that has been stringified.

if (!options.data && model && (method == 'create' || method == 'update')) {
  params.contentType = 'application/json';
  params.data = JSON.stringify(model.toJSON());
}

When ajax() is called, JSON.stringify is called again. This causes the string to get double encoded. For example: "{\"name\":\"ted\",\"age\":22}" Parsing that on the server turns into a string instead of an object.

I've created an example comparison between jQuery and jquip. Look at the payloads.

As for a solution, is the call to JSON.stringify necessary? It doesn't match the behavior of jQuery's ajax().

Can you send me a pull request? Code lives here:
https://github.com/mythz/jquip/blob/master/src/jquip.ajax.js

Just noticed that this commit fixed it. The version of jquip in the builder is out of date.

ahh cool thx for the heads up, i'll update jqbuilder tonight

FYI http://www.servicestack.net/jqbuilder/ has just been updated.

thx