之间$。阿贾克斯()和$。获得()和$ .load差() [英] Difference between $.ajax() and $.get() and $.load()

查看:113
本文介绍了之间$。阿贾克斯()和$。获得()和$ .load差()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之间是什么 $的差异。阿贾克斯() $。获得() $。负载()

这是更好地使用和在什么样的条件?

Which is better to use and in what conditions?

推荐答案

$。阿贾克斯()是最可配置的,在那里你在获得细粒度控制的HTTP头和这样的。你也可以直接访问使用此方法XHR对象。稍微更细粒度错误处理也被提供。因此可以更复杂,经常不必要的,但有时非常有用的。你必须处理返回的数据与自己的回调。

$.ajax() is the most configurable one, where you get fine grained control over HTTP headers and such. You're also able to get direct access to the XHR-object using this method. Slightly more fine-grained error-handling is also provided. Can therefore be more complicated and often unecessary, but sometimes very useful. You have to deal with the returned data yourself with a callback.

$。获得()只是一个速记 $。阿贾克斯(),但提取的一些配置走,它所您隐藏设置合理的默认值。返回数据的回调。它只允许GET-请求,因此伴随着 $。员额()功能类似的抽象,只为POST

$.get() is just a shorthand for $.ajax() but abstracts some of the configurations away, setting reasonable default values for what it hides from you. Returns the data to a callback. It only allows GET-requests so is accompanied by the $.post() function for similar abstraction, only for POST

.load()类似于 $。获得()但增加了功能,它允许你定义在哪里在文档中的返回的数据是要被插入。所以真的只可用在呼叫只会导致HTML。这就是所谓的略有不同,另外,全球,呼叫,因为它是依赖于特定的jQuery包裹DOM元素的方法。因此,人们会做: $('#divWantingContent')负载(...)

.load() is similar to $.get() but adds functionality which allows you to define where in the document the returned data is to be inserted. Therefore really only usable when the call only will result in HTML. It is called slightly differently than the other, global, calls, as it is a method tied to a particular jQuery-wrapped DOM element. Therefore, one would do: $('#divWantingContent').load(...)

应该指出的是,所有的 $。获得() $。员额() .load()都只是包装的 $。阿贾克斯(),因为它的内部调用。

It should be noted that all $.get(), $.post(), .load() are all just wrappers for $.ajax() as it's called internally.

的jQuery的Ajax的文档中的更多细节: http://api.jquery.com/category/ajax/

More details in the Ajax-documentation of jQuery: http://api.jquery.com/category/ajax/

这篇关于之间$。阿贾克斯()和$。获得()和$ .load差()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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