问题
im doing 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.
回答1:
try
data[data.length] = { name: "username", value: "The Username" };
回答2:
var data = $(form).serializeArray();
data.push({name: 'username', value: 'this is username'});
see also: jQuery post() with serialize and extra data
回答3:
var FormAttr = $('#form_id').serializeArray();
FormAttr.push({name: "Name_Of_Attribute", value:"Value_Of_Attributes"});
回答4:
Late to the party, but I personally prefer
const data = $(form).serializeArray().concat({
name: "username", value: "The Username"
});
回答5:
I think it's just
data['username'] = 'this is a username';
来源:https://stackoverflow.com/questions/1726583/jquery-serializearray-add-another-value-on-top-for-passing-to-ajax