Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between .load() and .ajax() functions in Jquery [duplicate]

Tags:

jquery

Possible Duplicate:
difference between $(“#id”).load and $.ajax?

I am using .ajax() for an asynchronous call in my code ,while reading about .load() it looks like it does the same thing.What is the difference between both the methods?

like image 820
Aditya Shukla Avatar asked Mar 09 '11 18:03

Aditya Shukla


People also ask

What is difference between jQuery get () and jQuery ajax ()?

get() executes an Ajax GET request. The returned data (which can be any data) will be passed to your callback handler. $(selector). load() will execute an Ajax GET request and will set the content of the selected returned data (which should be either text or HTML).

What is difference between Ajax and jQuery?

AJAX is a web development technique for making asynchronous calls to the server. jQuery is a JavaScript library for designing and make some web development tasks easy. It makes it possible to run javascript outside of the browser. It works on the browser or outside the browser also.

What is difference between Ajax and POST?

post is a shorthand way of using $. ajax for POST requests, so there isn't a great deal of difference between using the two - they are both made possible using the same underlying code.

What is jQuery load function?

The Load() method in jQuery helps to load data from server and returned into selected element without loading the whole page. Syntax: $(selector). load(URL, data, callback);


1 Answers

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

.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.

like image 63
Baz1nga Avatar answered Sep 29 '22 19:09

Baz1nga