Difference between $.ajax() and $.get() and $.load()

Posted RainDream

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Difference between $.ajax() and $.get() and $.load()相关的知识,希望对你有一定的参考价值。

转自:Difference between $.ajax() and $.get() and $.load()

 

 

$.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() 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() 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(...)

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

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

以上是关于Difference between $.ajax() and $.get() and $.load()的主要内容,如果未能解决你的问题,请参考以下文章

python: the difference between append and extend

Difference between Netbios and Host name

Difference between hash() and id()

Difference between == and ===

The difference between UDS on IP and UDS on CAN

What's the difference between all the Selection Segues?