Use of AJAX request $. post method in jquery, jquery. post
The $. post method of jQuery can be used to initiate AJAX requests to the server in the form of POST. $. The post method is a practical tool of jQuery.
The post and get transmission methods are not secure. The data submitted by the GET method is placed in the request line and visible in the client address bar. The size of the data submitted by the GET method is limited to 255 characters. The data submitted by the POST method is placed in the message body, which is invisible to the client. There is no limit on the size of the data submitted by the POST method.
$. Post method syntax
$. Post (url, parameters, callback) |
Parameters |
|
Url |
(String) The server resource address. |
Parameter |
(Object) parameters must be passed to the server. The parameter format is "key/value ". |
Callback |
(Function) is called when the request is complete. The function parameters are the response body and status in sequence. |
Return Value |
XHR instance |
Let's look at a simple example.
Client code:
<Html xmlns = "http://www.w3.org/1999/xhtml">
Main server 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 and Result
Use httpwatcher to intercept request information. If you select a number from the drop-down list, you can intercept the following request information.
When the $. post method is used:
We can see that there are parameters in POST Data, indicating that this is a POST request.
POST requests are often used when the server status changes or when some data is updated.