此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

Request:method 属性

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2017年3月⁩.

备注: 此特性在 Web Worker 中可用。

Request 接口的 method 只读属性包含请求所使用的方法(如 GETPOST 等)。

一个用于指示请求所使用的方法的字符串

示例

在下面的代码片段中,我们使用 Request() 构造函数(针对与脚本位于同一目录下的图像文件)创建了一个新的请求,然后将该请求的方法保存到一个变量中:

js
const myRequest = new Request("flowers.jpg");
const myMethod = myRequest.method; // GET

规范

Specification
Fetch
# ref-for-dom-request-method②

浏览器兼容性

参见