Jquery Get/Post
jQuery - AJAX get() in addition to post() Methods
The jQuery get() in addition to post() methods are used to asking information from the server amongst an HTTP GET or POST request.
HTTP Request: GET vs. POST
Two unremarkably used methods for a request-response betwixt a customer in addition to server are: GET in addition to POST.- GET - Requests information from a specified resource
- POST - Submits information to move processed to a specified resource
POST tin move too move used to become roughly information from the server. However, the POST method NEVER caches data, in addition to is frequently used to ship information along amongst the request.
To larn to a greater extent than close GET in addition to POST, in addition to the differences betwixt the ii methods, delight read our HTTP Methods GET vs POST chapter.
jQuery $.get() Method
The $.get() method requests information from the server amongst an HTTP GET request.Syntax:
$.get(URL,callback);
The required URL parameter specifies the URL you lot wishing to request.The optional callback parameter is the advert of a component to move executed if the asking succeeds.
The next event uses the $.get() method to recollect information from a file on the server:
Example
$("button").click(function(){
$.get("demo_test.asp", function(data, status){
alert("Data: " + information + "\nStatus: " + status);
});
});
The instant parameter is a callback function. The outset callback parameter holds the content of the page requested, in addition to the instant callback parameter holds the condition of the request.
Tip: Here is how the ASP file looks similar ("demo_test.asp"):
<%
response.write("This is roughly text from an external ASP file.")
%>
jQuery $.post() Method
The $.post() method requests information from the server using an HTTP POST request.Syntax:
$.post(URL,data,callback);
The required URL parameter specifies the URL you lot wishing to request.The optional information parameter specifies roughly information to ship along amongst the request.
The optional callback parameter is the advert of a component to move executed if the asking succeeds.
The next event uses the $.post() method to ship roughly information along amongst the request:
Example
$("button").click(function(){
$.post("demo_test_post.asp",
{
name: "Donald Duck",
city: "Duckburg"
},
function(data, status){
alert("Data: " + information + "\nStatus: " + status);
});
});
Then nosotros croak inward roughly information to ship along amongst the asking (name in addition to city).
The ASP script inward "demo_test_post.asp" reads the parameters, processes them, in addition to returns a result.
The 3rd parameter is a callback function. The outset callback parameter holds the content of the page requested, in addition to the instant callback parameter holds the condition of the request.
Tip: Here is how the ASP file looks similar ("demo_test_post.asp"):
<%
dim fname,city
fname=Request.Form("name")
city=Request.Form("city")
Response.Write("Dear " & fname & ". ")
Response.Write("Hope you lot alive good inward " & urban nitty-gritty & ".")
%>
Comments
Post a Comment