The use of Ajax request $.post methods in jquery _ajax related

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.