tags:

views:

957

answers:

2

When doing ajax stuff with jQuery you can pass your data along to the server in two key ways:

  1. Use an object like { firstname:'blah', lastname: 'derp' }

  2. Use a string like &firstname=blah&lastname=derp

(1) Arises naturally when you're passing in values programatically. (2) Arises naturally when you've got input fields.

My problem: it doesn't look like you can combine them.

ie 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.

+1  A: 

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

karim79
A: 

Thank you Karim.

Another resource:

http://stackoverflow.com/questions/1184624/serialize-form-to-json-with-jquery

And finally, anyone remember pak9?

http://www.youtube.com/watch?v=l5xcqNWhLRU