Search code examples
javascriptxmlhttprequestfetch

What can you do with XMLHttpRequest and cannot with Fetch API?


I know that as for 2020 the Fetch API can be considered a modern replacement for pretty much everything that was done with XMLHttpRequest. But I wonder if there are still things that can only be done with XMLHttpRequest at this point. Can XMLHttpRequest be completely dropped?


Solution

  • I can imagine couple reasons, why you can use XMLHttpRequest:

    First, you don't want to use polyfills, but need to support old browsers: https://caniuse.com/#search=fetch

    Second you need something specific from XMLHttpRequest, that fetch can’t do, like upload https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/upload to track upload progress.

    In other cases, use fetch.