jQuery .getJSON与.post哪个更快? [英] jQuery .getJSON vs .post which one is faster?

查看:92
本文介绍了jQuery .getJSON与.post哪个更快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用

$.getJSON();

 $.post();

我正在尝试通过仅用于AJAX请求的页面发送一些参数 并以JSON或html代码段获取一些结果.

I'm trying to send some parameters through a page that is just for AJAX request and get some results in JSON or html snippet.

我想知道哪一个更快?

假设HTML文件只是简单的布尔文本(对或错)

Assume the HTML file would be simply plain boolean text (true or false)

推荐答案

正如其他人所说,这两个函数之间没有真正的区别,因为这两个函数都是由

As others said there is no real difference between the two functions, because both of them will be sent by XMLHttpRequest.

如果服务器使用相同的代码处理两个请求,则处理时间应该相同.

If the server is handling both of the requests with the same code then the handling times should be the same.

因此,可以将问题转换为HTTP GET请求或POST请求中哪个更快?

Therefore the question can be translated to which one is faster the HTTP GET request or the POST request?

因为与GET请求相比,POST请求还需要两个额外的HTTP标头(Content-TypeContent-Length),后者应该更快(因为将传输较少的数据).

Because the POST request needs two additional HTTP headers (Content-Type and Content-Length) comparing to the GET request the latter should be faster (because less data will be transferred).

但这只是速度,我认为最好遵循 REST 指南.如果要修改内容,请使用POST;如果要获取内容,请使用GET.

But that's just the speed, I think it's better to follow the REST guidelines here. Use POST if you're modifying something, use GET if you want to fetch something.

另一个重要的事情是,可以缓存GET响应,但是我有问题缓存POST .

And one another important thing, GET responses could be cached, but I was having problems caching POST ones.

这篇关于jQuery .getJSON与.post哪个更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆