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();


var headers = request.getAllResponseHeaders();



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.


var request = new XMLHttpRequest();
request.open("GET", "foo.txt", true);
request.onreadystatechange = function() {
  if(this.readyState == this.HEADERS_RECEIVED) {


Specification Status Comment
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]
(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

Document Tags and Contributors

 Contributors to this page: teoli, GabRoyer, Sebastianz, MashKao, jsx
 Last updated by: teoli,