4

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

1

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.