We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

Response.type

这篇翻译不完整。请帮忙从英语翻译这篇文章

这是一个实验中的功能
此功能某些浏览器尚在开发中,请参考浏览器兼容性表格以得到在不同浏览器中适合使用的前缀。由于该功能对应的标准文档可能被重新修订,所以在未来版本的浏览器中该功能的语法和行为可能随之改变。

type 是Response 接口包含的一种响应类型,是只读属性.它可以是以下某一种值:

  • basic: 标准值, 同源响应, 带有所有的头部信息除了“Set-Cookie” 和 “Set-Cookie2″.
  • cors: Response 接收到一个有效的跨域请求. 部分headers和body可以被访问.
  • error: 网络错误. 没有有用的描述错误的信息。响应的状态为0,header为空且不可变。从 Response.error()中获得的响应的类型.
  • opaque: 响应 “no-cors” 的跨域请求. 严重受限.

Note: “错误”响应从来没有真正暴露于脚本: 这种响应 fetch() 将被promise拒绝.

Syntax

var myType = response.type;

Value

ResponseType说明响应类型.

Example

In our Fetch Response example (see Fetch Response live) we create a new Request object using the Request() constructor, passing it a JPG path. We then fetch this request using fetch(), extract a blob from the response using Body.blob, create an object URL out of it using URL.createObjectURL, and display this in an <img>.

Note that at the top of the fetch() block we log the response type to the console.

var myImage = document.querySelector('img');

var myRequest = new Request('flowers.jpg');

fetch(myRequest).then(function(response) {
  console.log(response.type); // returns basic by default
  response.blob().then(function(myBlob) {
    var objectURL = URL.createObjectURL(myBlob);
    myImage.src = objectURL;
  });
});

Specifications

Specification Status Comment
Fetch
type
Living Standard Initial definition

Browser compatibility

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) Internet Explorer Opera Safari (WebKit)
Basic support 42
41[1]
(Yes) 39 (39)
34[2]
未实现

29
28[1]

未实现
Feature Android Edge Firefox Mobile (Gecko) Firefox OS (Gecko) IE Phone Opera Mobile Safari Mobile Chrome for Android
Basic support 未实现 (Yes) 未实现 未实现 未实现 未实现 未实现 未实现

[1] The implementation of this feature is behind the "Experimental Web Platform Features" preference in chrome://flags.

[2] The implementation of this feature is behind the preference dom.fetch.enabled in about:config, defaulting to false.

See also

文档标签和贡献者

此页面的贡献者: fsx950223, Stevenzwzhai
最后编辑者: fsx950223,