jQuery - .getjson VS .ajax json

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5922175/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 20:01:15  来源:igfitidea点击:

jQuery - .getjson VS .ajax json

jqueryajax

提问by Jerry Harrison

Possible Duplicate:
Difference Between $.getJSON() and $.ajax() in jQuery

可能的重复:
jQuery 中 $.getJSON() 和 $.ajax() 的区别

super simple question.... between .getjson and .ajax() json which is faster?

超级简单的问题....getjson 和 .ajax() json 之间哪个更快?

considering retrieving and parsing data.

考虑检索和解析数据。

Much thanks.

非常感谢。

采纳答案by colinmarc

.getjson()calls .ajax(), so they should be equivalent.

.getjson()调用.ajax(),所以它们应该是等价的。

回答by Bozho

Same thing. getJSON()is a shorthand for .ajax(..)with specific parameters.

一样。getJSON().ajax(..)具有特定参数的简写。

To quote the documentation of .getJSON():

引用以下文档.getJSON()

This is a shorthand Ajax function, which is equivalent to:

   $.ajax({
      url: url,
      dataType: 'json',
      data: data,
      success: callback
    });

这是一个简写的 Ajax 函数,相当于:

   $.ajax({
      url: url,
      dataType: 'json',
      data: data,
      success: callback
    });

回答by cmcginty

I had a similiar question, and wanted to point out the following documentation in JQuery.ajax:

我有一个类似的问题,想指出JQuery.ajax 中的以下文档:

The $.ajax() function underlies all Ajax requests sent by jQuery. It is often unnecessary to directly call this function, as several higher-level alternatives like $.get() and .load() are available and are easier to use. If less common options are required, though, $.ajax() can be used more flexibly.

$.ajax() 函数是jQuery 发送的所有Ajax 请求的基础。通常没有必要直接调用这个函数,因为有几个更高级别的替代方法,如 $.get() 和 .load() 可用并且更易于使用。但是,如果需要不太常见的选项,则可以更灵活地使用 $.ajax()。

回答by KARASZI István

jQuery.getJSON()uses the same jQuery.ajax()call finally, so there are no speed differences.

jQuery.getJSON()jQuery.ajax()最后使用相同的调用,所以没有速度差异。