Use of Ajax request $. Post Method

Source: Internet
Author: User

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

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.