jQuery $.get() and $.post() Methods
The jQuery’s $.get() and $.post() methods provide simple tools to send and retrieve data asynchronously from a web server. Both the methods are pretty much identical, apart from one major difference — the $.get() makes Ajax requests using the HTTP GET method, whereas the $.post() makes Ajax requests using the HTTP POST method.
The basic syntax of these methods can be given with:
$.get(URL, data, success); —Or— $.post(URL, data, success);
The parameters in the above syntax have the following meaning:
- The required URL parameter specifies the URL to which the request is sent.
- The optional data parameter specifies a set of query string (i.e. key/value pairs) that is sent to the web server along with the request.
- The optional success parameter is basically a callback function that is executed if the request succeeds. It is typically used to retrieve the returned data.
Note: The HTTP GET and POST methods are used to send request from a browser to a server. The main difference between these methods is the way in which the data is passed to the server. Check out the tutorial on GET and POST methods for the detailed explanation and comparison between these two methods.