Search code examples
javascriptajaxxmlhttprequestfetch

Any reason to use ajax over fetch API


Fetch API IS the modern way to do XMLHttpRequest. It's superior to traditional ajax in every way. Out of curiosity, moving forward is there any REAL world reasons why you would still use old ajax call (like jquery.ajax) over fetch?

(Other than for old ie browser support of course...)


Solution

  • One might use jQuery's ajax if the codebase already uses it everywhere. Even though modern browsers support fetch, some might prefer to keep their code stylistically consistent and use just one method. Many developers value consistent, working code very highly, even if it doesn't necessarily involve the modern version of things.

    Another reason one might prefer XMLHttpRequest is that it's more widely supported in general. Yes, the browsers that don't support fetch are relatively uncommon nowadays, but there's still a not-completely-insignificant proportion of users stuck on obsolete browsers like IE11. (The numbers are dwindling, but they're still around, unfortunately.) To support these users, one might choose to implement XMLHttpRequest everywhere. (Or one might instead choose to install a fetch polyfill, which some might think would be a more elegant solution)