. SerializeArray () serializes table elements (similar to the '. serialize ()' method) and returns JSON data structure data. (From the jquery document ).
There is a form window with the code:
Copy codeThe Code is as follows: <form action = "" method = "post" id = "tf">
<Table width = "100%" cellspacing = "0" cellpadding = "0" border = "0">
<Tr>
<Th> name: </th>
<Td>
<Input type = "text" id = "txtUserName" name = "UserName"/>
</Td>
<Th> mobile phone number: </th>
<Td>
<Input type = "text" name = "Mobile" id = "txtMobile" maxlength = "11"/>
</Td>
</Tr>
<Tr>
<Td style = "text-align: center;" colspan = "2">
<Input type = "button" value = "Submit" style = "padding-top: 3px;" name = "butsubmit" id = "butsubmit"/>
</Td>
</Tr>
</Table>
</Form>
JavaScript code Processing Form:Copy codeThe Code is as follows: <script>
$ (Function (){
$ ("# Butsubmit"). click (function (){
Var data = convertArray ($ ("# tf"). serializeArray ());
$. Post (url, data, function (d) {}, "json ");
});
})
Function convertArray (o) {// mainly recommends this function. It converts the serialized value of jquery into the name: value format.
Var v = {};
For (var I in o ){
If (typeof (v [o [I]. name]) = 'undefined') v [o [I]. name] = o [I]. value;
Else v [o [I]. name] + = "," + o [I]. value;
}
Return v;
}
</Script>