Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery $.post() vs $.get()

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.

like image 405
qwertymk Avatar asked Mar 26 '12 15:03

qwertymk


People also ask

What is the difference between jQuery get () and jQuery Ajax ()?

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.

Does Ajax use POST or GET?

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.

What is jQuery POST?

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.

What is difference between Ajax and POST?

$. 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.


2 Answers

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.

like image 65
Dunhamzzz Avatar answered Nov 14 '22 06:11

Dunhamzzz


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/

like image 44
diggersworld Avatar answered Nov 14 '22 07:11

diggersworld