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.
Syntax
var headers = XMLHttpRequest.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
[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.