• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 328
  • Last Modified:

jquery ajax data parameters mixed

How would I do the following (mix the data parameter);

data: options.getparam + "&" + { 'mode' : options.mode : modeb : options.modeB }


where getparam is the following from the calling function

'getparam' : $('form').serialize()  which is the form elements  in name&value format
0
KeithMcElroy
Asked:
KeithMcElroy
2 Solutions
 
Chris StanyonCommented:
A couple of way of mixing data. serialize() returns a string (like a querystring) so you would need to concatenate your additional variables on to it:

data : options.getparam + "&mode=" + options.mode + "&modeb=" + options.modeB;

Alternatively, you could use serializeArray() to return an array instead of a string and then 'push' new values on to.

myData = $('form').serializeArray();
myData.push( { name: "mode", value: options.mode } );
myData.push( { name: "modeb", value: options.modeB } );

Then just post the myData array in your ajax call:

data: myData
0
 
JonNormanCommented:
have a look at the param function too, this takes an array (does not require a form) and serializes that:

http://api.jquery.com/jQuery.param/
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now