jquery ajax data parameters mixed

Posted on 2012-09-13
Last Modified: 2012-09-14
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
Question by:KeithMcElroy
    LVL 42

    Accepted Solution

    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
    LVL 13

    Assisted Solution

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

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    I have answered several questions lately that were solved utilizing the power of jQuery's AJAX functions, so I thought I would write an article demonstrating the ease of use. Why should I use jQuery as opposed to regular JavaScript? Now I know…
    Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now