この記事はまだボランティアによって 日本語 に翻訳されていません。ぜひ MDN に参加して翻訳を手伝ってください!
The XMLHttpRequest.getAllResponseHeaders() method returns all the response headers, separated by CRLF, as a string, or null
if no response has been received. If a network error happened, an empty string is returned.
Note: For multipart requests, this returns the headers from the current part of the request, not from the original channel.
DOMString getAllResponseHeaders();
Syntax
var headers = request.getAllResponseHeaders();
Parameters
None.
Return value
A ByteString
representing all of the response's headers (except those whose field name is Set-Cookie
or Set-Cookie2
) separated by CRLF, or null
if no response has been received. If a network error happened, an empty string is returned.
Example
var request = new XMLHttpRequest(); request.open("GET", "foo.txt", true); request.send(); request.onreadystatechange = function() { if(this.readyState == this.HEADERS_RECEIVED) { console.log(request.getAllResponseHeaders()); } }
Specifications
Specification | Status | Comment |
---|---|---|
XMLHttpRequest The definition of 'getAllResponseHeaders()' in that specification. |
Living Standard | WHATWG living standard |
Browser compatibility
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | 1 | 1.0 (1.7 or earlier)[1] | 5[2] 7 |
(Yes) | 1.2 |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | ? | 1.0 | 1.0 (1.0) | ? | ? | ? |
[1] Starting from Firefox 49, empty headers are returned as empty strings in case the preference network.http.keep_empty_response_headers_as_empty_string
is set to true
, defaulting to false
. Before Firefox 49 empty headers had been ignored. Since Firefox 50 the preference defaults to true
.
[2] This feature was implemented via ActiveXObject(). Internet Explorer implements the standard XMLHttpRequest since version 7.