Obsolete since Gecko 52 (Firefox 52 / Thunderbird 52 / SeaMonkey 2.49)
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

这是 实验性技术
检查 浏览器兼容性表格 要小心谨慎在生产中使用这之前。

getAll() 方法在 interface used to return an array of all the values of a header within a object with a given name; in newer versions of the Fetch spec, it has been deleted, and Headers.get() has been updated to fetch all header values instead of only the first one.

If the requested header doesn't exist object, it returns an empty array.

For security reasons, some headers can only be controller by the user agent. These headers include the forbidden header names and forbidden response header names .

句法

myHeaders.getAll(name);
					

参数

name
The name of the HTTP header whose values you want to retrieve from the 对象。 If the given name is not the name of an HTTP header , this method throws a TypeError .

返回

数组 包含 ByteString sequence representing the values of the retrieved header.

范例

Creating an empty object is simple:

var myHeaders = new Headers(); // Currently empty
					

You could add a header to this using Headers.append , then retrieve it using getAll() :

myHeaders.append('Content-Type', 'image/jpeg');
myHeaders.getAll('Content-Type'); // Returns [ "image/jpeg" ]
					

If the header has multiple values associated with it, the array will contain all the values, in the order they were added to the Headers object:

myHeaders.append('Accept-Encoding', 'deflate');
myHeaders.append('Accept-Encoding', 'gzip');
myHeaders.getAll('Accept-Encoding'); // Returns [ "deflate", "gzip" ]
					

注意 : Use Headers.get to return only the first value added to the 对象。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
getAll 弃用 非标 Chrome 42 — 60 Edge ≤18 — 79 Firefox 39 — 52
不支持 39 — 52
34 Disabled
Disabled From version 34: this feature is behind the dom.fetch.enabled preference. To change preferences in Firefox, visit about:config.
IE No Opera 29 — 47 Safari No WebView Android 42 — 60 Chrome Android 42 — 60 Firefox Android No Opera Android 29 — 44 Safari iOS No Samsung Internet Android 4.0

图例

完整支持

完整支持

不支持

不支持

实验。期望将来行为有所改变。

实验。期望将来行为有所改变。

非标。预期跨浏览器支持较差。

非标。预期跨浏览器支持较差。

弃用。不要用于新网站。

弃用。不要用于新网站。

用户必须明确启用此特征。

用户必须明确启用此特征。

另请参阅

元数据

  • 最后修改: