Fetch API

Fetch API

The Fetch API provides an interface for fetching resources (including across the network). It will seem familiar to anyone who has used XMLHttpRequest, but the new API provides a more powerful and flexible feature set.

Differences from jQuery

The fetch specification differs from jQuery.ajax() in three main ways:

  • The Promise returned from fetch() won’t reject on HTTP error status even if the response is an HTTP 404 or 500. Instead, it will resolve normally (with ok status set to false), and it will only reject on network failure or if anything prevented the request from completing.
  • fetch() won't receive cross-site cookies. You can’t establish a cross site session using fetch(). Set-Cookie headers from other sites are silently ignored.
  • fetch() won’t send cookies, unless you set the credentials init option.
    • Since Aug 25, 2017: The spec changed the default credentials policy to same-origin. Firefox changed since 61.0b13.)

Note: Find out more about using the Fetch API features in Using Fetch, and study concepts in Fetch basic concepts.

Fetch Interfaces

WindowOrWorkerGlobalScope.fetch()
The fetch() method used to fetch a resource.
Headers
Represents response/request headers, allowing you to query them and take different actions depending on the results.
Request
Represents a resource request.
Response
Represents the response to a request.

Using Fetch

原文地址:https://www.cnblogs.com/chucklu/p/13208507.html