首页 > Web开发 > 详细

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

时间:2017-07-06 15:41:06      阅读:332      评论:0      收藏:0      [点我收藏+]

转自: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()

原文:http://www.cnblogs.com/drizzlewithwind/p/7126481.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!