getResponseHeaders():获取响应的所有http头;
index.html
<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Strict//EN' 'http://www.w3.org/TR/html4/strict.dtd'>
<html>
<head>
<Meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<title>insert into title</title>
<script type="text/javascript" src="ajax.js"></script>
</head>
<body>
<p id="show">show</p>
<button onclick="loadtxtDoc('test.txt')">Get XML HTTP header</button>
</body>
</html>
test.txt
this is test using XML Request to show a text file;
ajax.js
var xmlHttp;s
function getXmlHttpObject(){
var xmlObject=null;
if(window.XMLHttpRequest){
xmlObject=new XMLHttpRequest();
}else if(window.ActiveXObject){
xmlObject=new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlObject;
}
function loadtxtDoc(url){
xmlHttp=getXmlHttpObject()
if(xmlHttp!=null){
xmlHttp.onreadystatechange=stateChange;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}else{
alert("browser does not support HTTP Request");
}
}
function stateChange(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
document.getElementById("show").innerHTML=xmlHttp.getAllResponseHeaders();
}else{
alert("Prolem retrieving XML data"+xmlHttp.statusText);
}
}
}
Output:
ETag: "4000000030305-3a-522c7fa0e3668" Content-Length: 58 Keep-Alive: timeout=5,max=98 Content-Type: text/plain Last-Modified: Fri,23 Oct 2015 16:19:32 GMT
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。