网络编程
位置:首页>> 网络编程>> JavaScript>> ajax xmlhttp getResponseHeader实例教程

ajax xmlhttp getResponseHeader实例教程

 来源:asp之家 发布时间:2009-02-04 10:46:00 

标签:XMLHttp,getResponseHeader,ajax,asp

如何发送一个XMLHttpRequest的检索的特定部分HTML标题数据。


<html>
<head>
<title>getResponseHeader实例教程 aspxhome.com</title>
<script type="text/javascript">
var xmlhttp;
function loadXMLDoc(url)
{
xmlhttp=null;
if (window.XMLHttpRequest)
  {// all modern browsers
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {// for IE5, IE6
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
if (xmlhttp!=null)
  {
  xmlhttp.onreadystatechange=state_Change;
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
  }
else
  {
  alert("Your browser does not support XMLHTTP.");
  }
}
function state_Change()
{
if (xmlhttp.readyState==4)
  {// 4 = "loaded"
  if (xmlhttp.status==200)
    {// 200 = "OK"
    document.getElementById('p1').innerHTML="This file was last modified on: " + xmlhttp.getResponseHeader('Last-Modified');
    }
  else
    {
    alert("Problem retrieving data:" + xmlhttp.statusText);
    }
  }
}
</script>
</head>
<body>
<p id="p1">
该getResponseHeader ( )函数返回一个标题的资源。标题包含的文件信息,如长度,服务器类型,内容类型,日期修改等.</p>
<button onclick="loadXMLDoc('test_xmlhttp.txt')">Get "Last-Modified"</button>
</body>
</html>

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com