=波波日志 > JavaScript/Ajax > JavaScript 取得 Xml 文件的 LastModify=
[转]JavaScript 取得 Xml 文件的 LastModify
曾经有段时间,要是在担心,Google/Yahoo会不会不知道我的Sitemap.xml更新了,又或者Baidu不知道偶的基于BBS的开放协议生成的xml文件是否更新,虽然知道不会有这样的问题,总觉得这中间有一些东西是我所不知道的:)
直到最近鼓捣Http的时候,才发觉,除了Get/Post以外,原来还有个只关注响应首部的请求:Head请求,当服务器对Head请求做出响应时,只发送响应首部而忽略内容,由于忽略了内容,对Head请求的响应比对Get或Post的响应就小得多也快很多了.
示例如下:
JS版:
+展开
-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) {
requestType = request;
createXMLHttpRequest();
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 == "isResourceAvailable") {
getIsResourceAvailable();
}
}
}
function getAllResponseHeaders() {
alert(xmlhttp.getAllResponseHeaders());
}
function getLastModified() {
alert("Last Modified: " + xmlhttp.getResponseHeader("Last-Modified"));
}
function getIsResourceAvailable() {
if(xmlhttp.status == 200) {
alert("成功响应");
}
else if(xmlhttp.status == 404) {
alert("没找到相应资源");
}
else {
alert("未知错误: " + xmlhttp.status);
}
}
var requestType = "";
function createXMLHttpRequest() {
if (window.ActiveXObject) {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
}
}
function doHeadRequest(request, url) {
requestType = request;
createXMLHttpRequest();
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 == "isResourceAvailable") {
getIsResourceAvailable();
}
}
}
function getAllResponseHeaders() {
alert(xmlhttp.getAllResponseHeaders());
}
function getLastModified() {
alert("Last Modified: " + xmlhttp.getResponseHeader("Last-Modified"));
}
function getIsResourceAvailable() {
if(xmlhttp.status == 200) {
alert("成功响应");
}
else if(xmlhttp.status == 404) {
alert("没找到相应资源");
}
else {
alert("未知错误: " + xmlhttp.status);
}
}
类别:JavaScript/Ajax 作者:转载 日期:2009-07-01 【评论:0 阅读:】
暂时没有评论!
发表留言
同类热门博文
- ·AJAX跨域问题解决办..
- ·ajax+asp.net+mssql..
- ·ajax问题总结
- ·JavaScript解析XML的..
- ·JS URL编码函数
- ·ajax+asp+mssql无刷..
- ·ajax无刷新上传文件..
- ·美化alert,confirm..
博格Tag
- flash/flex/fcs/AIR(750)
- Asp.Net/C#/WCF(476)
- JavaScript/Ajax(232)
- 操作系统及应用软件(206)
- SQL及数据库(105)
- 黑客技术(96)
- Asp/VBScript(85)
- 网站排名及优化(82)
- PHP/apache/Perl(72)
- HTML/WML/CSS兼容(65)
- 其他(59)
- 个人日志(44)
- lucence.net/分词技术(33)
- C#设计模式(22)
- 计算机网络(17)
- 日语学习(15)
- Canvas/VML/SVG(13)
- linux(10)
- 游戏开发(8)
- 正则表达式(5)
- Jsp/Java(4)
最新博文
声明:本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载或引用的作品侵犯了您的权利,请通知我们,我们会及时删除!
Powered by showbo,G51人力资讯网,桂ICP备05005887号
Powered by showbo,G51人力资讯网,桂ICP备05005887号
