I need to retrieve a simple page and use the data that it returns. Is there any difference between $.post()
and $.get()
should I be using one over the other?
I don't plan on submitting any data with the request.
The jQuery. get() method is used when you would like to make a quick Ajax call and you are very sure that the type is GET. url − It is a string that contains the URL in this the request is sent. data − It is optional parameter.
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.
jQuery post() method. The post() method is one of the commonly used HTTP methods. It is used to load a page from the server using an HTTP POST request. This method never caches the data and is generally used to send the data with the request.
$. post is a shorthand way of using $. ajax for POST requests, so there isn't a great deal of difference between using the two - they are both made possible using the same underlying code.
If you're not submitting data, then you actually should be using $.load();
$.get();
and $.post()
are typically for submitting data to a server, so you don't need them in this context. There are big differences between POST and GET data, you should take some time to read up on them.
The main difference between them is that with POST you pass a collection of data and with GET you pass data in the URL. If you're passing a lot of data I'd suggest POST. If you're just calling a URL for a response then use get.
For a full understanding though checkout the jQuery documentation of each.
GET: http://api.jquery.com/jQuery.get/
POST: http://api.jquery.com/jQuery.post/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With