Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery serializeArray() add another value on top for passing to Ajax

I'm doing the following:

var data = $(form).serializeArray();
// Now I want to  add another value on this data
data.username = 'this is username';

I want to know how can I add another value after doing serializeArray(). I tried all the things I know, but nothing is getting it to work. any ideas pls.

like image 454
Basit Avatar asked Nov 13 '09 01:11

Basit


3 Answers

var data = $(form).serializeArray();
data.push({name: 'username', value: 'this is username'});

see also: jQuery post() with serialize and extra data

like image 162
Emmanuel Gleizer Avatar answered Nov 11 '22 08:11

Emmanuel Gleizer


try

data[data.length] = { name: "username", value: "The Username" };
like image 41
Lobstrosity Avatar answered Nov 11 '22 10:11

Lobstrosity


var FormAttr = $('#form_id').serializeArray();

FormAttr.push({name: "Name_Of_Attribute", value:"Value_Of_Attributes"});
like image 7
user1210155 Avatar answered Nov 11 '22 09:11

user1210155