Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

XMLHttpRequest.getResponseHeader()

我们的志愿者还没有将这篇文章翻译为 中文 (简体)加入我们帮助完成翻译!

Draft
This page is not complete.

The XMLHttpRequest.getResponseHeader() method returns the string containing the text of the specified header. If there are multiple response headers with the same name, then their values are returned as a single concatenated string, where each value is separated from the previous one by a pair of comma and space. The getResponseHeader() method returns the value as a UTF byte squence. The search for the header name is case-insensitive.

Syntax

var myHeader = getResponseHeader(name);

Parameters

name
A ByteString representing the name of the header you want to return the text value of.

Return value

A ByteString representing the header's text value, or null if either the response has not yet been received or the header doesn't exist in the response.

Example

var client = new XMLHttpRequest();
client.open("GET", "unicorns-are-teh-awesome.txt", true);
client.send();
client.onreadystatechange = function() {
  if(this.readyState == this.HEADERS_RECEIVED) {
    console.log(client.getResponseHeader("Content-Type"));
  }
}

Specifications

Specification Status Comment
XMLHttpRequest
The definition of 'getResponseHeader()' in that specification.
Living Standard WHATWG living standard

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 1 ?[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 (Yes) ? ? ?

[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

文档标签和贡献者

 此页面的贡献者: mindplay-dk, Sebastianz, chrisdavidmills, MashKao, jsx
 最后编辑者: mindplay-dk,