Web Worm
Web Worm

Reputation: 2066

difference between xmlhttprequest and $.ajax(), $.load

what is actually difference between

xmlhttprequest and $.ajax()

i want to know which is the lightest function from above to load data....

Upvotes: 5

Views: 3539

Answers (3)

BalusC
BalusC

Reputation: 1108732

The jQuery's $.ajax is just a crossbrowser-compatible wrapper around XMLHttpRequest. You don't need to introduce countless nasty if/try blocks to get it to work in any webbrowser the world wide web is aware of. If you're using jQuery, you're supposed to use it (or one of the other Ajax functions).

Upvotes: 1

AdaTheDev
AdaTheDev

Reputation: 147234

$.ajax uses an XmlHttpRequest under the hood. See here

You get the benefit of having it all encapsulated away by using $.ajax so I'd use that instead of writing all the cross-browser support yourself

Upvotes: 1

hobodave
hobodave

Reputation: 29303

XMLHttpRequest is the raw ajax request object. Working with this directly would be the 'lightest', but you're losing all the cross browser compatibility provided by the $.ajax() method in JQuery. If you want your code to work across all browsers, you must use $.ajax().

Upvotes: 8

Related Questions