Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
statianzo opened this issue Jan 25, 2012 · 4 comments
Closed

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

statianzo opened this issue Jan 25, 2012 · 4 comments

Comments

@statianzo
Copy link
Collaborator

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().

@mythz
Copy link
Owner

mythz commented Jan 26, 2012

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

@statianzo
Copy link
Collaborator Author

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

@mythz
Copy link
Owner

mythz commented Jan 26, 2012

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

@mythz
Copy link
Owner

mythz commented Jan 27, 2012

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

thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants