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
If you just want to retrieve the contents from an html document, use $.load()
instead.
You can even retrieve partial information from that document by providing an additional selector:
$('#result').load('ajax/test.html');
$('#result').load('ajax/test.html #justThisContainerPlease');
see http://api.jquery.com/load/
To answer your question more generally, its no big difference whether you're using a POST
or a GET
request to a server, it depends on the amount of data you need to send. Typically, a GET
request is limited to 2083 (because IE limits the query-string). So if you have a lot of data to send, you should use a POST
request.
Technically, a GET
request should be slightly faster. Because internally only one packet is sent instead of at least two (one for the header and one for the transmission body). But that really is high performance optimizing.