1. Serialize () method
Description: Serializes the contents of the form to a string that is used for AJAX requests.
Format: var data = $ ("form"). Serialize ();
2.serializeArray () method
Description: Serializes a FORM element (similar to the '. Serialize () ' method) to return the JSON data structure.
Note that this method returns a JSON object rather than a JSON string. You need to use plug-ins or <a> third-party libraries </a> for string operations.
Format: var jsondata = $ ("form"). Serializearray ();
Both of these methods can set the data parameter to $ ("form") when submitting form data using AJAX. Serialize () or $ ("form"). Serializearray ().
Demo
<form id= "MyForm" ><table><tr><td> name:</td><td> <input type= "text" name= "name"/> </ td></tr><tr><td> Sex: </td><td><input type= "Radio" name= "Sex" value= "1" > Male < Input type= "Radio" name= "Sex" value= "0" > Women </td></tr><tr><td> Age:</td><td> <select name= "Age" ><option value= ">20</option><option value=" >21</option>< Option value= ">22</option></select></td></tr><tr><td colspan=" 2 ">< Input type= "button" id= "ajaxbtn" value= "commit"/></TD></TR></TABLE></FORM>
$ (function () { $ ("#ajaxBtn"). Click (function () {var params1 = $ ("#myform"). Serialize (); var params2 = $ ("#myform"). Serializearray (); Console.log (PARAMS1); Name=zhangsan&sex=1&age=20console.log (PARAMS2); [Object, Object, Object]$.ajax ({type: "POST", url: "Registeraction.action", Data:params1,success:function (msg) {Ale RT ("Success:" + msg);})})
the difference between the two methods can be seen from the
Itmyhome
Source: http://blog.csdn.net/itmyhome1990/article/details/41866265
jquery serialization Form serialize () Serializearray ()