Knowledge Points:
$ ("#form"). Serialize (); Serializes form data to a standard URL-encoded text string (Key1=value1&key2=value2 ... )。
The following example shows the AJAX submission form serialization data.
Contents of the form:
<form id="F1"> <label for="Realname"> Name: </label><input type="text"Name="Realname"Id="Realname"Value=""><label for="Phonenum"> Mobile number:</label> <input type="text"Name="Phonenum"Id="Phonenum"Value=""><label for="Email"> Email:</label> <input type="text"Name="Email"Id="Email"Value=""><INPT type="Button"Name="btnconfirm"Id="btnconfirm"Value="Determine"/></form>
View Code
Script code:
<script type="Text/javascript">$ (function () {$ ('#btnConfirm'). Click (function () {$ ( This). attr ('Disabled','Disabled'). Val ('being processed ...');//Click the OK button to disable varData = $ ('#f1'). Serialize ();//serialization of form data forms (Key1=value1&key2=value2 ... ) After submission$.post ('/users/saveuserinfo', data, function (obj) {$ ('#btnConfirm'). attr ('Disabled',false). Val ('Confirm');//de-Disable if(obj. Status = ='OK') {alert ("Modification succeeded"); } Else{alert (obj.msg); } }, 'JSON');//The JSON here means that the data transfer format is JSON. }) })</script>
Ajax transmits data in the following ways (both transmit data in form form serialization):
$.ajax ({ 'post', 'your URL' ) , data: $ ("form"). Serialize (), success:function (data ) { // your code }});
$.post ('your URL', $("form"). Serialize (), function (data) {//Your code }});$.Get('your URL', $("form"). Serialize (), function (data) {//Your code}}); $.getjson ('your URL', $("form"). Serialize (), function (data) {//Your code }});
Ajax Submission Form serialization (serialize ()) data