Request.mode

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

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

Request 接口的 mode 只读属性包含请求的模式 (e.g., cors, no-cors, cors-with-forced-preflight, same-origin, or navigate.) 这用于确定跨域请求是否导致有效的响应,以及响应的哪些属性是可读的:

  • same-origin — 如果使用此模式向另外一个源发送请求,显而易见,结果会是一个错误。你可以设置该模式以确保请求总是向当前的源发起的。
  • no-cors — 防止该方法是HEAD,GET或POST以外的其他方法 。If any ServiceWorkers intercept these requests, they may not add or override any headers except for these. In addition, JavaScript may not access any properties of the resulting Response. This ensures that ServiceWorkers do not affect the semantics of the Web and prevents security and privacy issues arising from leaking data across domains.
  • cors — 允许跨域请求,例如访问第三方供应商提供的各种API。 These are expected to adhere to the CORS protocol. Only a limited set of headers are exposed in the Response, but the body is readable.
  • navigate — 支持导航的一个模式。 The navigate value is intended to be used only by HTML navigation. A navigate request is created only while navigating between documents.

Syntax

var myMode = request.mode;

Value

A RequestMode value.

Example

In the following snippet, we create a new request using the Request.Request() constructor (for an image file in the same directory as the script), then save the request mode in a variable:

var myRequest = new Request('flowers.jpg');
var myMode = myRequest.mode; // returns "cors" by default

Specifications

Specification Status Comment
Fetch
mode
Living Standard Initial definition

Browser compatibility

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 42.0 (Yes) 39 (39) 未实现

29
28[1]

未实现
navigate mode 49.0 ? 46 (46) 未实现 ? 未实现
Feature Android Android Webview Edge Firefox Mobile (Gecko) Firefox OS (Gecko) IE Phone Opera Mobile Safari Mobile Chrome for Android
Basic support 未实现 49.0 (Yes) 未实现 未实现 未实现 未实现 未实现 49.0
navigate mode 未实现 未实现 ? 未实现 未实现 未实现 未实现 未实现 49.0

See also

文档标签和贡献者

标签: 
 此页面的贡献者: FLYSLOW, xgqfrms-GitHub
 最后编辑者: FLYSLOW,