Fetch API - Web APIs | MDN
The Fetch API provides an interface for fetching resources (including across the network). It is a more powerful and flexible replacement for XMLHttpRequest.
概览
收录于
2026年3月18日
学科与领域
coding · apis-integration
年级范围
九年级(高一)–十二年级(高四)
页面类型
Article
简介
Overview of the Fetch API
- Purpose: Provides a modern, powerful, and flexible interface for fetching network resources, serving as a replacement for
XMLHttpRequest. - Core Mechanism: Uses
RequestandResponseobjects, incorporating concepts like CORS and HTTP Origin header semantics. - Primary Method: The
fetch()method is a global function available in bothWindowandWorkercontexts. - Request Handling:
- Takes a mandatory path argument and an optional
initoptions object. - Returns a
Promisethat resolves to aResponseobject as soon as headers are received (even if the HTTP status indicates an error).
- Takes a mandatory path argument and an optional
- Deferred Fetching: The
fetchLater()API allows for requests to be sent after a delay or upon page navigation/closure. - Key Interfaces:
RequestandResponse: Represent the network request and server response.Headers: Allows querying and manipulation of request/response headers.fetchLater()/DeferredRequestInit: Used for managing deferred network requests.
- Usage: While
Request()andResponse()constructors exist, they are typically generated automatically by API actions likefetch()or service worker events.
用户评价
暂无已发布的评价,欢迎率先分享您的使用体验。