Reputation: 115
I have a form and I am sending it with ajax to server. Like this:
$.ajax({
url: form.attr('action'),
type: 'POST',
data: form.serialize(),
dataType : 'json',
success: function(data){
}
});
And I receive in server something like
Array
(
[forms_element_1] => 'some value 1',
[forms_element_2] => 'some value 2',
[forms_element_3] => 'some value 3'
)
Now i need to add to this form global variable that is array itself.
var statuses = [5,7,3];
I need to receive from POST in server side something like
Array
(
[forms_element_1] => 'some value 1',
[forms_element_2] => 'some value 2',
[forms_element_3] => 'some value 3',
[statuses] => Array
(
[0] => 5,
[1] => 7,
[2] => 3
)
)
How can I achieve that in jQuery?
Upvotes: 1
Views: 841
Reputation: 95022
Turn it into a param string with $.param
, then append it to the serialized form (which is also a param string).
data: form.serialize() + "&" + $.param({statuses:[5, 7, 3]}),
Upvotes: 2