Abishek
Abishek

Reputation: 11691

Fundamental question in using Jquery with PHP when making ajax calls

I have a Fundamental question in using Jquery with PHP when making ajax calls with respect to performance. Is it right to do a Get or a POST. Which is faster when using ajax calls. I know this question has got nothing to do with PHP though, but would like to understand the different view points.

All I am trying to do is to pass variables to PHP and echo data using jquery.

$.post('request.php',
   { param1: value, param2:value
   }, function (data) { 
   container.html(data); }


if (isset($_POST['param1']) && isset($_POST['param2'])){

//Do some process on the server
echo "server processed data";
}

What is best to use in this case? A GET or a POST

Upvotes: 1

Views: 107

Answers (3)

Benjamin Crouzier
Benjamin Crouzier

Reputation: 41855

If you are not sending huges amounts of data, you should not be concerned about performance.

This question might also be usefull : When do you use POST and when do you use GET?

Upvotes: 1

Explosion Pills
Explosion Pills

Reputation: 191729

As Pekka says, the performance shouldn't matter. RFC 2616, the HTTP 1.1 spec has all the information you need on the standards you should follow about using GET vs. POST. Short answer is that if you make the same GET request twice in a row, you should get an identical result back. If you use POST twice in a row, you won't (or you might but there will be another update to the back-end).

Shorter answer is: use GET for retrieval and POST for modification.

Upvotes: 1

Pekka
Pekka

Reputation: 449385

Performance-wise, it doesn't matter. But there are other arguments for one or the other:

GET vs POST in Ajax

Upvotes: 1

Related Questions