<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>w3cschool在线教程(w3cschool.cn)</title>
<script>
function loadXMLDoc(url)
{
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById('p1').innerHTML=xmlhttp.getAllResponseHeaders();
}
}
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
</script>
</head>
<body>
<p id="p1"> getAllResponseHeaders() 函数返回资源的头部信息,例如 length, server-type, content-type, last-modified 等。</p>
<button onclick="loadXMLDoc('/statics/demosource/xmlhttp_info.txt')">获取头部信息</button>
</body>
</html>