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 Request and Response objects, incorporating concepts like CORS and HTTP Origin header semantics.
  • Primary Method: The fetch() method is a global function available in both Window and Worker contexts.
  • Request Handling:
    • Takes a mandatory path argument and an optional init options object.
    • Returns a Promise that resolves to a Response object as soon as headers are received (even if the HTTP status indicates an error).
  • Deferred Fetching: The fetchLater() API allows for requests to be sent after a delay or upon page navigation/closure.
  • Key Interfaces:
    • Request and Response: 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() and Response() constructors exist, they are typically generated automatically by API actions like fetch() or service worker events.

用户评价

暂无已发布的评价,欢迎率先分享您的使用体验。