We're looking for a person or people to help audit MDN to find places we could speed up. Is this you or someone you know? Check out the RFP: https://mzl.la/2IHcMiE


Fetch API 提供了一個能獲取包含跨網路資源在的資源介面。它似乎有點像我們所熟悉的 XMLHttpRequest ,但這個新的 API 提供了更強更彈性的功能。


Fetch 提供了 RequestResponse 物件,還有其他牽涉網路請求的通用定義。這能讓他們在需要的時候被使用到,不管是 service worker、Cache API、還是其他處理或更動請求回應的相類事物、或是任何需要產生有序化產生回應的用例(use case)。

它也提供了諸如 CORS 與 HTTP origin 標頭語意的分散定義,能取代分散的定義。

For making a request and fetching a resource, use the GlobalFetch.fetch method. It is implemented in multiple interfaces, specifically Window and WorkerGlobalScope. This makes it available in pretty much any context you might want to fetch resources in.

The fetch() method takes one mandatory argument, the path to the resource you want to fetch. It returns a promise that resolves to the Response to that request, whether it is successful or not. You can also optionally pass in an init options object as the second argument (see Request).

Once a Response is retrieved, there are a number of methods available to define what the body content is and how it should be handled (see Body).

You can create a request and response directly using the Request() and Response() constructors, but you are unlikely to do this directly. Instead, these are more likely to be created as results of other API actions (for example, FetchEvent.respondWith from service workers).

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

Fetch 介面

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

Experimental fetch controller/signal/observer interfaces

Also known as "cancellable fetch", the following interfaces contain functionality to allow fetch request operations to be observed and controlled during their lifetimes.

Represents a controller object that allows you to control one or more fetch requests.
Represents a signal object that allows you to communicate with a fetch request and control it via a FetchController.
Represents an observer object that allows you to retrieve information concerning the status of a fetch request.
Provides a callback function that runs when the fetch request it is assocated with runs. This provides a FetchObserver object that can be used to retrieve information concerning the status of a fetch request.

Fetch mixin

Provides methods relating to the body of the response/request, allowing you to declare what its content type is and how it should be handled.


Specification Status Comment
Fetch Living Standard Initial definition


We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Edge Firefox (Gecko) IE Opera Safari (WebKit)
Basic support 42 14 39 (39)
52 (52)[2]
No support 29
ReadableStream response body 43 14 No support[3] No support ? No support
Feature Android Webview Chrome for Android Edge Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support 42 42 (Yes) (Yes) No support No support 10.1
ReadableStream response body 43 43 (Yes) No support[3] No support ? No support

[1] This API is implemented behind a preference.

[2] Prior to Firefox 52, get() only returned the first value in the specified header, with getAll() returning all values. From 52 onwards, get() now returns all values and getAll() has been removed.

[3] Readable streams are currently enabled in Firefox, but hidden behind the dom.streams.enabled and javascript.options.streams prefs.



 此頁面的貢獻者: iigmir, guAnsunyata, jackblackevo
 最近更新: iigmir,