In jquery The Ajax submission form has a post and get way, and we can use Ajax to serialize the form $ (' #表单ID ') directly using the Get method. Serialize ().
Details are as follows:
One, $get way to submit a form
The Get () method loads information through a remote HTTP GET request
Format
$ (selector). Get (Url,data,success (RESPONSE,STATUS,XHR), DataType)
Instance
Use AJAX get requests to change the text of a DIV element:
$.get (' login.php ', {
ID: ' Robin ',
Password: ' 123456 ',
Gate: ' Index '
}, function (data, status) {
Data is the returned object, status is the requested State
alert (data);
Now assume that the server script will return a text "Hello, robin!. ",
Then the browser will pop up the dialog box to display the text
alert (status);
The result is success, error, and so on, but here is the function to run when successful
});
Displays the test.php return value (HTML or XML, depending on the return value):
Ajax serialization Form
$. Form.serialize (Namevaluepair)
Virtual a form, and set the name and value of the form control.
Parameters
Namevaluepair
Required option. Set up a virtual form control. This parameter is in the form of: {name1=value, name2=value2, ...}
return value
The string after the virtual form is serialized, in the form of: username=%e5%95%8a%e8%94%a1&password=123456
$.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
}
});
Second, the $POST way to submit the form
$.post
Jquery.post (URL, [data], [callback], [Type]): Asynchronous request using POST method
Parameters:
URL (String): The URL address where the request is sent.
Data (MAP): (optional) The information to be sent to the server, expressed as a Key/value key-value pair.
Callback (function): (optional) callback function on successful loading (this method is invoked only if response's return state is success)
$.post ("data.php", $ ("#firstName. Val ()"), function (data) {
$ ("#postResponse"). HTML (data.name);
"JSON"//Set the type of get data, so the data format is JSON type
);
Ajax
$.ajax (Opiton)
$.ajax ({
URL: "Ajax/ajax_selectpictype.aspx",
Data:{full: "Fu"},
Type: "POST",
DataType: ' JSON ',
Success:callback,
Error:function (er) {
Backerr (ER);
});
IV, $.getjson (Url,[data],[callback])
$.getjson ("data.php", $ ("#firstName. Val ()"), function (jsondata) {
$ ("#getJSONResponse") . html (jsondata.id);} Without setting, the data type directly obtained is JSON,
so calls need to use the Jsondata.id method
);