Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

jquery

what is actually difference between

xmlhttprequest and $.ajax()

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

like image 891
Web Worm Avatar asked Jan 09 '10 18:01

Web Worm


People also ask

What is the difference between XMLHttpRequest and AJAX?

XMLHttpRequest is the raw browser object that jQuery wraps into a more usable and simplified form and cross browser consistent functionality. jQuery. ajax is a general Ajax requester in jQuery that can do any type and content requests.

Why do we use XMLHttpRequest in AJAX?

XMLHTTPRequest is basically used in Ajax programming. It retrieve any type of data such as json, xml, text etc. It request for data in background and update the page without reloading page on client side. An object of XMLHTTPRequest is used for asynchronous communication between client and server.

What is the difference between XMLHttpRequest and fetch?

The Fetch API allows you to make network requests similar to XMLHttpRequest (XHR). The main difference is that the Fetch API uses Promises, which enables a simpler and cleaner API, avoiding callback hell and having to remember the complex API of XMLHttpRequest.

What is the difference between AJAX and fetch?

Fetch is compatible with all recent browsers including Edge, but not with Internet Explorer. Therefore, if you are looking for maximum compatibility, you will continue to use Ajax to update a web page. If you also want to interact with the server, the WebSocket object is also more appropriate than fetch.


1 Answers

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

like image 79
hobodave Avatar answered Oct 30 '22 08:10

hobodave