XMLHttpRequest.getAllResponseHeaders()

Draft
This page is not complete.

The XMLHttpRequest.getAllResponseHeaders() method returns all the response headers, separated by CRLF, as a string, or null if no response has been received.

Note: For multipart requests, this returns the headers from the current part of the request, not from the original channel.

JavaScript
DOMString getAllResponseHeaders();

Syntax

JavaScript
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.

Example

JavaScript
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.

See also

License

© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/api/xmlhttprequest/getallresponseheaders

Reference XMLHttpRequest