简体   繁体   中英

pushing array into serializeArray send by ajax

I use this code for my form

var formData = $("#form").serializeArray();

now I want to push an array into formData variable like this

[{"name":"xxxx"},{"name":"xxxx"}]

or push the array to object of the formData

Update: I want to send the data via ajax to server

any solution?

Very well I answer my question, forget about the serializeArray() so

    var formData = {};
    formData['X1'] = [];
    item1 = {}
    item1 ["name"] = "XXX";
    formData['X1'].push(item1);

the result is:

{[{"name":"XXX"},{"name":"XXX"}]}

then send formData via ajax, it's easy, isn't it?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM