$.get(u,d,c,“JSON”) 与 $.getJSON(u,d,c)
我通常将 $.get()
和 $.post()
用于所有异步调用,但它们通常以最终参数“JSON”进行限定,表明我希望在回调中处理 JSON 数据。
使用 $.get([url],[data],[callback],"JSON")
比 $.getJSON([url],[data],[回调])
?仅仅是不再需要包含最终参数,即返回类型的显式声明吗?
I generally use $.get()
and $.post()
for all of my asynchornous calls, but they're usually qualified with the final parameter being "JSON," indicating that I'm expecting to handle JSON data within my callback.
Is there any benefit to using $.get([url],[data],[callback],"JSON")
over $.getJSON([url],[data],[callback])
? Is it nothing more than no longer needing to include the final parameter, an explicit declaration of the return type?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有区别。从jQuery 源中可以明显看出这一点。我对所有跨域调用使用
getJSON
,当调用遵循同源策略时使用get
。No difference. It's obvious from the jQuery source. I use
getJSON
for all cross domain calls andget
when calls follow same origin policy.正如@Chandra 指出的,这是一种方便的方法。我还检查了源代码以确定,它只是调用
$.get
。因此,$.get
相对于$.getJSON
的唯一性能是少了一次方法调用。但是,由于它似乎更清晰,我认为使用$.getJSON
应该优于$.get
As @Chandra pointed out, it is a convenience method. I checked the source as well to be sure, and it simply calls
$.get
. So, the only performance of$.get
over$.getJSON
is there would be one less method call. However, since it seems to be clearer, I would say that using$.getJSON
should be preferred over$.get