开发者

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 r开发者_StackOverflow中文版espect 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


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

GET vs POST in Ajax


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.


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜