Methods for AJAX get() and post() in jQuery

With an HTTP GET or POST request, the jQuery get() and post() functions are also get information from the system.

GET vs. POST in HTTP Requests

GET and POST are two generally used techniques for a demand between a client and a server.

 

GET - Gets information from a certain resource.

POST - Sends data to a defined resource to be processed.

GET is mostly used to obtain (retrieve) information from a server. 

Attention : It's important to note that the GET method can return data that has already been cached.

POST can then be used to retrieve information from a server. The POST method, on the other hand, NEVER stores data and is frequently used to provide data with the request.

Feel free to read our HTTP Methods GET vs POST chapter to understand much about GET and POST, as well as the distinctions between the 2 techniques.


jQuery $.get() Method

The $.get() methodology requests information and data  from the server with associate degree HTTP GET request.

Syntax:

$.get(URL,callback);

The intended URL is indicated by the needed URL option.

If the request succeeds, the optional callback parameter defines the name of a function that will be invoked.

The following instance makes use of the $.get() approach to retrieve information from a file cum document at the server:

Illustration:

EXAMPLE ❯


A very initial parameter of $.get() is the URL we desire to request ("demo test.asp").

A callback function is the second parameter. The very first callback element contains the information of the requested page, whereas the second callback variable carries the request's response.

Hint : This is what the demo test.asp ASP file looks the same as:

<%

response.write("This is some text from an external ASP file.")

%>


Method $.post() of jQuery

An HTTP POST response is used by the $.post() method to request information from the database cum server.

Syntax:

$.post(URL,data,callback);

The needed URL is indicated either by needed URL argument.

The optional data make the system whether data should be sent with the response.

If the request succeeds, the additional callback parameter controls the name of a function which will be invoked.

The $.post() method is used in the given example to transmit information as well as the recommendation:

Illustration:

EXAMPLE ❯


The URL to be fetched ("demo test post.asp") may be the first input of $.post().

Then we send some data with the query (name and city).

The "demo test post.asp" ASP script accepts the inputs, analyses them, and afterwards returns a conclusion.

The method basically is the 3rd parameter. The first callback parameter carries the content of the requested page, and the subsequent callback parameter indicates the request's outcome.

Hint: And that is how the ASP script ("demo test post.asp") appears:

<%

dim fname,city

fname=Request.Form("name")

city=Request.Form("city")

Response.Write("Dear " & fname & ". ")

Response.Write("Hope you live well in " & city & ".")

%>


AJAX Link for jQuery

Please see our jQuery AJAX Guide for a complete list of any and all jQuery AJAX methods.