KenavR KenavR - 1 month ago 14
Ajax Question

jquery form.serialize and other parameters

Is it possible to send a

form.serialize()
object and other paramters with a single
$.ajax()
request?

Example:

$.ajax({
type : 'POST',
url : 'url',
data : {
$('#form').serialize(),
par1 : 1,
par2 : '2',
par3: 232
}
}


If not what's the best way to submit a form together with other parameters.

Thanks

Answer

serialize() effectively turns the form values into a valid querystring, as such you can simply append to the string:

$.ajax({
    type : 'POST',
    url : 'url',
    data : $('#form').serialize() + "&par1=1&par2=2&par3=232"
}