The $.post method using jquery can initiate an AJAX request to the server in post form. The $.post method is a practical tool for jquery.
The characteristics of post and get send way, get method submits data is unsafe, data is placed on request line, client address bar is visible; The data size submitted by the Get method is limited to 255 characters. The data submitted by the Post method is placed inside the message body, the client is not visible, and the data size submitted by the Post method is not limited.
$.post method Syntax
$.post (Url,parameters,callback) |
Parameters |
|
Url |
(string) server-side resource address. |
Parameter |
(object) requires a parameter to be passed to the server side. The parameter is in the form of "key/value". |
Callback |
(function) is invoked when the request completes. The function argument is in response body and state. |
return value |
XHR instance |
Look at a simple example.
Client code:
Service-side main code:
protected void Page_Load (object sender, EventArgs e)
{
if (! Page.IsPostBack)
{
if (request["id"]!= null &&!string. IsNullOrEmpty (request["id"). ToString ()))
{
Response.Write (GetData (request["id"). ToString ()));
}
}
protected string GetData (string id)
{
string str = string. Empty;
Switch (ID)
{case
"1":
str + = "This is number 1";
break;
Case "2":
str + + "This is number 2";
break;
Case "3":
str + + "This is number 3";
break;
Default:
str = "Warning other number!";
break;
return
str;
}
Run the program, as shown in the figure:
When you use Httpwatcher to intercept request information, when you select a number in the Drop-down box, you can intercept the following request information.
Screenshots when using the $.post method:
From the above figure we can see that there are parameters in post data, which indicates that this is a POST request.
Use a POST request when the server-side state changes, or when some data is modified to update.