tags:

views:

65

answers:

3

what is actually difference between

xmlhttprequest and $.ajax()

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

+2  A: 

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

hobodave
A: 

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

AdaTheDev
A: 

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

BalusC