MDN wants to learn about developers like you:

翻譯不完整。請協助 翻譯此英文文件


The GlobalFetch interface of the Fetch API contains the GlobalFetch.fetch() method used to start the process of fetching a resource.

GlobalFetch is implemented by both Window and WorkerGlobalScope — meaning that it will be available in pretty much any context you might want to fetch resources in.

A fetch() promise will reject with a TypeError when a network error is encountered, although this usually means permissions issue or similar. An accurate check for a successful fetch() would include checking that the promise resolved, then checking that the Response.ok property has a value of true. An HTTP status of 404 does not constitute a network error.

GlobalFetch is controlled by the connect-src directive of Content Security Policy rather than the directive of the resources it's retrieving.

Note: The fetch() method's parameters are identical to those of the Request() constructor.




Starts the process of fetching a resource.


In our basic fetch example (run example live) we use a simple fetch call to grab an image and display it in an <img> tag. You'll notice that since we are requsting an image, we need to run Body.blob (Response implements body) to give the response its correct MIME type.

var myImage = document.querySelector('.my-image');
fetch('flowers.jpg').then(function(response) {
  return response.blob();
}).then(function(response) {
  var objectURL = URL.createObjectURL(response);
  myImage.src = objectURL;


Specification Status Comment
The definition of 'GlobalFetch' in that specification.
Living Standard Initial definition


Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 42.0 39 (39)
No support 29
No support
Streaming response body 43.0 ? ? ? ?
Feature Android Android Webview Firefox Mobile (Gecko) Firefox OS (Gecko) IE Phone Opera Mobile Safari Mobile Chrome for Android
Basic support No support 42.0 No support No support No support No support No support 42.0
Streaming response body No support 43.0 ? ? ? ? ? 43.0

[1] This API is implemented behind a preference.



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