JavaScriptEasy
What are the differences between XMLHttpRequest and fetch() in JavaScript and browsers?
By FrontendPro Editorial Team Updated 8/8/2026
#JavaScript
Answer
XMLHttpRequest (XHR) and fetch() API are both used for asynchronous HTTP requests in JavaScript (AJAX). fetch() offers a cleaner syntax, promise-based approach, and more modern feature set compared to XHR. However, there are some differences:
XMLHttpRequestuses event callbacks, whilefetch()utilizes promise chaining.fetch()provides more flexibility in headers and request bodies.fetch()supports cleaner error handling withcatch().- Handling caching with
XMLHttpRequestis difficult, but caching is supported byfetch()by default via thecachevalue of the second parameter tofetch()orRequest(). fetch()requires anAbortControllerfor cancelation, whileXMLHttpRequestprovides anabort()method.XMLHttpRequesthas good support for progress tracking, whichfetch()lacks.XMLHttpRequestis only available in the browser and not natively supported in Node.js environments. On the other handfetch()is part of the JavaScript language and is supported on all modern JavaScript runtimes.
These days fetch() is preferred for its cleaner syntax and modern features.
Read the detailed answer on GreatFrontEnd which allows progress tracking, contains more code samples, and useful resources.
