readingResponseHeaders.html中的代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
var xmlHttp ;
var requestType = "";
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}
function doHeadRequest(request,url){
createXMLHttpRequest();
requestType = request;
xmlHttp.onreadystatechange= handleStateChange;
xmlHttp.open("HEAD",url,true);
xmlHttp.send(null);
}
function handleStateChange(){
if(xmlHttp.readyState == 4){
if(requestType == "allResponseHeaders"){
getAllResponseHeaders();
} else if(requestType == "lastModified") {
getLastModified();
} else if(requestType == "isResourceAvaiable") {
getIsResourceAvailable();
}
}
}
function getAllResponseHeaders(){
alert(xmlHttp.getAllResponseHeaders());
}
function getLastModified(){
alert("Last Modified " + xmlHttp.getResponseHeader("LAST-Modified"));
}
function getIsResourceAvailable(){
if(xmlHttp.status == 200) {
alert("successful response ");
} else if(xmlHttp.status == 404) {
alert("resource is unavailable ");
} else {
alert("unexcepted response status : " + xmlHttp.status);
}
}
function parseResults(){
var responseDiv = document.getElementById("serverResponse");
if (responseDiv.hasChildNodes()){
responseDiv.removeChild(responseDiv.childNodes[0]);
}
var responseText = document.createTextNode(xmlHttp.responseText);
responseDiv.appendChild(responseText);
}
</script>
</head>
<body>
<h1>reading response headers </h1><br><br>
<a href="javascript:doHeadRequest('allResponseHeaders','readingResponseHeaders.xml');">getAllResponseHeaders</a><br/><br/>
<a href="javascript:doHeadRequest('lastModified','readingResponseHeaders.xml');">lastModified</a><br/><br/>
<a href="javascript:doHeadRequest('isResourceAvaiable','readingResponseHeaders.xml');">getIsResourceAvailable</a><br/><br/>
<a href="javascript:doHeadRequest('isResourceAvaiable','notAvailableResource.xml');">getIsResourceAvailable</a><br/><br/>
</body>
</html>
做为客户端请求文件:readingResponseHeaders.xml,只是为了表明这个文件在服务端存在,内容可以为空。
有一点很奇怪,xmlHttp.open("HEAD",url,true); 我把"HEAD"改为"head",alert弹出的内容会有点不一致。
分享到:
相关推荐
适合前端初学者 jquery中的datatable使用ajax读取数据 并展示表格数据
深入浅出Ajax(Head Rush Ajax)全部源码,书中全部代码,一共七章。
Jquery ajax 读取txt文件 Jquery分页 Jquery ajax 读取txt文件 Jquery分页
用ajax实现自动读取数据库数据,而且是在定时读取,你可是自己设置
head first ajax 源码 head first ajax 源码 head first ajax 源码
jQuery+ajax按条件读取json文件内容
使用AJAX技术来实现读取本地文本文档内容,然后将读取到的内容显示在网页上
资源好不好,看过就知道,推荐。想学习Ajax的同学可以好好看下,这个代码很不错,从浅入深。
AJAX图文并茂的好书 学习AJAX朋友的首选书目
Pick up Head Rush Ajax and learn Ajax and asynchronous programming the right way--the way that sticks. If you've ever read a Head First book, you know what to expect: a visually rich format designed...
如题,ajax读取页面内容【简单的ajax入门实例】
Head First 系列是不错的一套丛书,适合刚入门的菜鸟,对有相关开发经验的人也是极好的..
js中的ajax库,使用时需要三个参数, function ajax(url,fnSucc,fnFailed) 第一个为要读取的文件的地址,第二个是读取成功之后要执行的操作的函数,第三个是读取失败后要执行的操作的函数。 if (oAjax.status == ...
Ajax定时读取数据库(源代码发布) Ajax定时读取数据库(源代码发布)
jQuery ajax读取json文件内容
unigui_ajax读取本地文件信息 unigui_ajax读取本地文件信息
英文版的HeadFirst ajax,对ajax书讲的很详细,可以看看
好东西 来分享ajax的简单案例 读取xml读取数据库信息 发送到页面上
head first ajax 源代码
提高AJAX客户端响应速度,AJAX技术,编程技巧