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