Response: type property


目录

The type read-only property of the Response interface contains the type of the response. The type determines whether scripts are able to access the response body and headers.

Value

A string, which may be any of the following values:

Examples

A basic response

The following same-origin request will return a basic response:

const response = await fetch("flowers.jpg");

console.log(response.type); // "basic"

A CORS response

Assuming https://example.org is not the requester's origin, and that the server responds with the appropriate CORS headers, this request will return a cors response:

const response = await fetch("https://example.org/flowers.jpg");

console.log(response.type); // "cors"

An opaque response

The following request is made with the no-cors option, so it returns an opaque response:

const response = await fetch("https://example.org/flowers.jpg", {
  mode: "no-cors",
});

console.log(response.type); // "opaque"
console.log(response.body); // null
console.log(response.status); // 0

An error response

The following code uses Response.error() to create an error response:

const response = Response.error();

console.log(response.type); // "error"
console.log(response.body); // null
console.log(response.status); // 0

Specifications

Browser compatibility

See also


版本号 #3
由 壳壳虫 创建于 2026-10-31 03:27:53 UTC
由 cocobook-sync 更新于 2026-11-04 17:34:58 UTC