开发者

Is it okay use POST in all my AJAX queries

I have developed a habit where I force all my AJAX requests to use only POST and never GET. Even when I am only fetching a tooltip I use POST. Is there anything wrong with this appraoch ?

Are there any implications on performance of th开发者_StackOverflow中文版e server or browser? Any caching related issue ?


Since you asked about performance and caching, I suppose this is different enough from Pekka's dupe checker to warrant additional reply.

Any performance differences will be insignificant as far as the server is concerned, but browsers do not cache POST requests (and rightly so), so therefore if you wanted to be able to allow the server to respond with 301 Not Modified if someone makes 2 subsequent calls to the same URL, then you need to use GET.

It's better practice to follow the standards for HTTP methods, depending on what you're doing with the data as well. If you're retrieving data, generally GET is correct. For sending it, POST or possibly PUT is correct.

Reposting the dupe link here as well: GET vs POST in AJAX?


Actually, GET is a little bit faster than POST, but it depends on which environment are you using ajax requests, and in many cases the difference is negligible.


I've not encountered any complications with the POST method in any of my ajax calls. In fact, I find it rather useful in some situations to default to POST, for instance - If I am sending form data to the server BUT I also need to send a couple of additional handles via GET, i can append the request url with my additional parameters and have my data segregated once it gets to the server.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜