=波波日志 > JavaScript/Ajax > ajax对象getAllResponseHeaders方法=
ajax对象getAllResponseHeaders方法
ajax对象getAllResponseHeaders()方法用于获取所有HTTP头信息,在获取时只用HEAD即可获取到。例如,需要获取全部的HTTP响应头信息,其实现方法如代码所示。
代码 获取全部响应头信息
代码18.2的运行后得到结果如下
Cache-Control: private
Content-Length: 55100
Content-Type: text/html
Date: Thu, 13 Mar 2008 16:48:03 GMT
代码 获取全部响应头信息
+展开
-HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>获取HTTP头信息</title>
<script type="text/javascript">
var xmlHttp=false;
//创建XMLHttpRequest对象
function createXMLHttpRequest() {
if(window.ActiveXObject) { //IE
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
window.alert("创建XMLHttpRequest对象错误"+e);
}
}
} else if(window.XMLHttpRequest) { //非IE
xmlHttp = new XMLHttpRequest();
}
if(!(xmlHttp)) {
window.alert("创建XMLHttpRequest异常!");
}
}
function HeadRequest() {
createXMLHttpRequest();
xmlHttp.onreadystatechange = getHeadInfo;
xmlHttp.open("HEAD", "http://www.rzchina.net", false);
xmlHttp.send(null);
}
function getHeadInfo() {
if(xmlHttp.readyState == 4) {
alert(xmlHttp.getAllResponseHeaders());
}
}
</script>
</head>
<body>
<center>
<h1>获取HTTP头信息</h1>
<input type="button" value="GetAllResponseHeaders" onclick="HeadRequest()">
</center>
</body>
</html>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>获取HTTP头信息</title>
<script type="text/javascript">
var xmlHttp=false;
//创建XMLHttpRequest对象
function createXMLHttpRequest() {
if(window.ActiveXObject) { //IE
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
window.alert("创建XMLHttpRequest对象错误"+e);
}
}
} else if(window.XMLHttpRequest) { //非IE
xmlHttp = new XMLHttpRequest();
}
if(!(xmlHttp)) {
window.alert("创建XMLHttpRequest异常!");
}
}
function HeadRequest() {
createXMLHttpRequest();
xmlHttp.onreadystatechange = getHeadInfo;
xmlHttp.open("HEAD", "http://www.rzchina.net", false);
xmlHttp.send(null);
}
function getHeadInfo() {
if(xmlHttp.readyState == 4) {
alert(xmlHttp.getAllResponseHeaders());
}
}
</script>
</head>
<body>
<center>
<h1>获取HTTP头信息</h1>
<input type="button" value="GetAllResponseHeaders" onclick="HeadRequest()">
</center>
</body>
</html>
代码18.2的运行后得到结果如下
Cache-Control: private
Content-Length: 55100
Content-Type: text/html
Date: Thu, 13 Mar 2008 16:48:03 GMT
类别:JavaScript/Ajax 作者:波波 日期:2011-08-19 【评论:0】
相关文章
暂时没有评论!
发表留言
热门博文
- AJAX跨域问题解决办法
- ajax问题总结
- jQuery dataType指定为json的问题
- ajax+asp.net+mssql无刷新聊天室
- ajax无刷新上传文件,使用iframe模仿
- ajax对象abort方法
最新博文
- jquery+flash显示图片实时加载进度插件
- jquery浮动层拖动插件
- firefox NPMethod called on non-NPObject wrapped JSObject!错误
- IE浏览器setCapture和releaseCapture介绍
- 51.la统计出问题了
- 隐藏删除ckeditor状态栏
随机博文
- 深入理解__doPostBack 客户端调用服务端事件
- 扩展IE下的input selectionStart selectionEnd属性
- jquery easyUI tree遍历函数
- Js Call方法详解(js 的继承)
- ajax对象应用程序池
- javascript 数组方法
广告商赞助

