通过xmlhttp进行一次指定的head请求:
<html>
<head>
<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">
the getresponseheader() function returns a header from a resource.
headers contain file information like length,
server-type, content-type, date-modified, etc.</p>
<button onclick="loadxmldoc('/example/ajax/test_xmlhttp.txt')">get "last-modified"</button>
</body>
</html>
新闻热点
疑难解答
图片精选