1. Serializing to a string
$ ("#Form"). Serialize (); //name=zhangsan&sex=1&age=20
2. Serializing arrays
$ ("#form"). Serializearray (); //[object, object, object]
3. Serializing to an object
functionGetformjson (form) {varo = {}; varA =$ (form). Serializearray (); $.each (a,function () { if(o[ this. name]!==Undefined) { if(!o[ this. Name].push) {o[ this. name] = [o[ this. name]]; } o[ this. Name].push ( this. value | | ‘‘); } Else{o[ this. name] = this. value | | ‘‘; } }); returno; }
4.ajax passing a normal array
var deletenum= []; // Defines the array to be passed deletenum.push ("1" );d Eletenum.push ( "2" );d eletenum.push ( "3"); // $.ajax ({type: "post" " Deletenum.do " true , // must be specified as true success:< Span style= "color: #0000ff;" >function if (data.success) {deletenum = []; } }});
Back-end Code
public ajaxresult deletenum (string[] deletenum) { new ajaxresult (); // this time, we've got the deletenum array value. return ajaxresult;}
5.form form submission Custom Object array
<formID= "form"name= "form"Method= "post">
<input type= "hidden" name= "table" value= "user" >
<Table> <TR> <TD><inputtype= "text"name= "userlist[0].name"/></TD> <TD><inputtype= "text"name= "userlist[0].password"/></TD> </TR> <TR> <TD><inputtype= "text"name= "userlist[1].name"/></TD> <TD><inputtype= "text"name= "userlist[1].password"/></TD> </TR> <TR> <TD><inputtype= "text"name= "userlist[2].name"/></TD> <TD><inputtype= "text"name= "userlist[2].password"/></TD> </TR> </Table></form>
Ajax Submissions
$ ("#form"). Serializearray ()
Back-end Receive
public classFormlist {PrivateString table; PrivateArraylist<user>userlist; publicString getTable () {returntable; } public voidsettable (String Table) { this. Table =table; } publicArraylist<user>getuserlist () {returnuserlist; } public voidSetuserlist (arraylist<user>Userlist) { this. userlist=userlist; }}
public ajaxresult saveupdateuser (formlist list) { list<User> userlist = list.getuserlist ();}
JAVASCRIPT-JS serialization of form forms [json strings, arrays, objects]