Jquery get ()And post () are used to request data from the server through http get or POST requests.
Two common methods for request-response on the client and server are get and post.
- Get-Request data from the specified resource (if you get the data, there are naturally restrictions; your own requirements are not mentioned)
- Post-Submit the data to be processed to the specified resource. (do you want to mail the data, regardless of the size of the mail)
Get is basically used to get (retrieve) data from the server. Note: The get method may return cached data.
Post can also be used to obtain data from the server. However, the POST method does not cache data and is often used to send data together with requests.
To learn more about get and post and the differences between the two methods, read our HTTP method-Get and post.
Jquery $. Get ()Method
The $. Get () method requests data from the server through http get requests.
Syntax:
$. Get (URL,Callback);
RequiredURLThe parameter specifies the URL you want to request.
OptionalCallbackThe parameter is the name of the function executed after the request is successful.
The following example uses the $. Get () method to retrieve data from a file on the server:
Instance
$ ("Button"). Click (function ()
{
$. Get ("demo_test.asp", function (data, status)
{
Alert ("data:" + Data + "\ nstatus:" + status );
});
});
$. Get () the first parameter is the URL ("demo_test.asp") We want to request ").
The second parameter is the callback function. The first callback parameter contains the content on the requested page, and the second callback parameter contains the Request status.
Tip: the ASP file ("demo_test.asp") is similar to this:
<%
Response. Write ("this is some text from an external ASP file .")
%>
Jquery $. Post ()Method
The $. Post () method sends an http post request to request data from the server.
Syntax:
$. Post (URL,Data,Callback);
RequiredURLThe parameter specifies the URL you want to request.
OptionalDataParameters are required together with the data sent by the request.
OptionalCallbackThe parameter is the name of the function executed after the request is successful.
The following example uses $. Post () to send data together with the request:
Instance
$ ("Button"). Click (function ()
{
$. Post ("demo_test_post.asp ",
{
Name: "Donald Duck ",
City: "Duckburg"
},
Function (data, status)
{
Alert ("data:" + Data + "\ nstatus:" + status );
});
});
$. Post () the first parameter is the URL ("demo_test_post.asp") We want to request ").
Then we send data together with the request (name and city.
The ASP script in "demo_test_post.asp" reads these parameters, processes them, and returns results.
The third parameter is the callback function. The first callback parameter contains the content of the requested page, while the second parameter contains the Request status.
Tip: This ASP file ("demo_test_post.asp") is similar to this:
<%
Dim fname, City
Fname = request. Form ("name ")
City = request. Form ("city ")
Response. Write ("dear" & fname &".")
Response. Write ("hope you live well in" & City &".")
%>