Jquery-ajax get () and post () methods

Source: Internet
Author: User
Tags http post

The Jquery-ajax get () and post () methods request data from a remote server over HTTP GET and HTTP POST requests.

Two common methods of request-response on the client and server side are get and post

Get: Request data from a specified resource, get is used to fetch (retrieve) data from the server, but note that the fetch or fetch may be cached data because the Get method caches the data.

Post: Submits processing data to the specified resource, and post is often used to send data together with the request or to obtain data.

JQuery $.get () method

The $.get () method is used to fetch (retrieve) data from the server.

Syntax format: $.get (Url,callback)

The parameter 1:url specifies the address of the data that you want to load (required);

Parameter 2:data specifies a collection of query string key-value pairs to be sent with the request (optional)

The parameter 3:callback specifies the function name (optional) that is executed after the Get () method completes

<! DOCTYPE html>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title></title>
<meta charset= "Utf-8"/>
<script src= "Css/jquery-2.1.4.js" ></script>
<script>
$ (document). Ready (function () {
$ ("button"). Click (function () {
$.get ("Text/demoajax.aspx", function (data, status) {
Alert ("Data:" + + data + "\ n Status:" + status);
})
})
})
</script>
<body>
<button> sends an HTTP GET request and gets the returned data </button>
</body>

Demoajax.aspx

Response.Expires = -1;//Not Cached
Response.Write ("This is the data retrieved from the ASPX file, Ajax is a great feature");//output a statement to the page
Response.End ();//end execution of the following HTML code.

JQuery $.post () method

The $.post () method submits the processed data to the specified resource via an HTTP POST

Syntax format

$.post (Url,data,callback);

The parameter 1:url specifies the address of the data that you want to load (required);

Parameter 2:data specifies a collection of query string key-value pairs to be sent with the request (optional)

The parameter 3:callback specifies the function name (optional) that is executed after the post () method completes

Instance:

<! DOCTYPE html>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title></title>
<meta charset= "Utf-8"/>
<script src= "Css/jquery-2.1.4.js" ></script>
<script>
$ (document). Ready (function () {
$ ("button"). Click (function () {
$.post ("Postajax.aspx", {name: "melao2006", City: "Shenzheng"}, function (data, status) {
Alert ("Data:" + + data + "\ n Status:" + status);
})
})
})
</script>
<body>
<button> sends an HTTP POST request to the ASPX page and requests the returned data </button>
</body>

Postajax.aspx

Response.Clear ();
Response.Expires =-1;
String name = request.form["Name"];
String city = request.form["City"];
Response.Write ("Hello:" + name + "\ncity:" + City);
Response.End ();

Jquery-ajax get () and post () methods

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.