js如何获取response header信息

js如何获取response header信息, 用sessionstatus=XMLHttpRequest.getResponseHeader("sessionStatus"); 获取到的为null。

麻烦大侠们看看怎么解决,截图如下:

clipboard.png

clipboard.png

阅读 24.2k
3 个回答
var req = new XMLHttpRequest();
req.open('GET', document.location, false);
req.send(null);
var headers = req.getAllResponseHeaders().toLowerCase();
alert(headers);

看你写成了全小写、sessionStatus、写成驼峰试一下、

var xmlhttp;

xmlhttp = null;
if (window.XMLHttpRequest) {
  // code for Firefox, Mozilla, IE7, etc.
  xmlhttp = new XMLHttpRequest();
} else if (window.ActiveXObject) {
  // code for IE6, IE5
  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlhttp != null) {
  xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4) {
      // 4 = "loaded"
      if (xmlhttp.status == 200) {
        // 200 = "OK
        alert(xmlhttp.getAllResponseHeaders());
      } else {
        alert("Problem retrieving data:" + xmlhttp.statusText);
      }
    }
  };
  xmlhttp.open("GET", document.location.href, true);
  xmlhttp.send(null);
} else {
  alert("Your browser does not support XMLHTTP.");
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题