Reputation:
When doing ajax stuff with jQuery you can pass your data along to the server in two key ways:
Use an object like
{
firstname:'blah',
lastname: 'derp'
}
Use a string like &firstname=blah&lastname=derp
(1) Arises naturally when you're passing in values programmatically.
(2) Arises naturally when you've got input fields.
My problem: it doesn't look like you can combine them, i.e.
jQuery.extend({
firstname:'blah',
lastname:'derp'
},jQuery('form.some-form').serialize());
And it's been nagging me for a while.
Truthfully I think they just need an objectified version of the serialize method that just gives you a json representation.
Upvotes: 4
Views: 6263
Reputation: 342635
This previous discussion should solve the problem of converting from json to a query string, and vice-versa:
How can I convert query string or JSON object map to single JSON object with jQuery?
Also, you might want to have a look at the jQuery Form plugin
Upvotes: 1