What is the difference between $.ajax() and $.get() and $.load()?
Which is better to use and in what conditions?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
$.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/