[JS] fetch() usage replaces ajax

fetch basic use

  • The Fetch API provides an interface for obtaining resources (including cross-domain requests), which is used to replace the traditional XMLHttpRequest and issue HTTP requests in JavaScript scripts.
  • It is not yet supported by all browsers. If you consider the problem of low-version browsers, you can introduce https://github.com/github/fetch/blob/master/fetch.js to be compatible.
  • The fetch api is based on promise design and returns a promise object, which was born to replace the unreasonable writing method of traditional xhr.
  • When there is no fetch, we get asynchronous resources like this:
 //发送一个get请求是这样的: //首先实例化一个XMLHttpRequest对象var httpRequest = new XMLHttpRequest (

The post [JS] fetch() usage to replace ajax first appeared on Lenix Blog .

This article is reprinted from https://blog.p2hp.com/archives/9080
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment