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.
$. 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.
ClientCode:
<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 ;}
RunProgram, 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.
On-Server StatusChanged, OrModify updatesSome data uses post requests.
Download demo