加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xml getResponseHeaders()函数

发布时间:2020-12-16 06:04:58 所属栏目:百科 来源:网络整理
导读:getResponseHeaders():获取响应的所有http头; 注:每个http头名称和值用冒号分割,并以rn结束。当send方法完成后才可调用该方法。 在此为了获取响应的所有的http头,我写了一个简单的demo,如下: index.html !DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01

getResponseHeaders():获取响应的所有http头;

注:每个http头名称和值用冒号分割,并以rn结束。当send方法完成后才可调用该方法。

在此为了获取响应的所有的http头,我写了一个简单的demo,如下:

index.html

<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Strict//EN' 'http://www.w3.org/TR/html4/strict.dtd'>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<title>insert into title</title>
<script type="text/javascript" src="ajax.js"></script>
</head>
<body>
     <p id="show">show</p>
     <button onclick="loadtxtDoc('test.txt')">Get XML HTTP header</button>
</body>
</html>

test.txt

this is test using XML Request to show a text file;

ajax.js

var xmlHttp;s

function getXmlHttpObject(){
    var xmlObject=null;
    if(window.XMLHttpRequest){
        xmlObject=new XMLHttpRequest();
    }else if(window.ActiveXObject){
        xmlObject=new ActiveXObject("Microsoft.XMLHTTP");
    }
    return xmlObject;
}


function loadtxtDoc(url){
    xmlHttp=getXmlHttpObject()
    if(xmlHttp!=null){
        xmlHttp.onreadystatechange=stateChange;
        xmlHttp.open("GET",url,true);
        xmlHttp.send(null);
    }else{
        alert("Browser does not support HTTP Request");
    }
}

function stateChange(){
    if(xmlHttp.readyState==4){
        if(xmlHttp.status==200){
            document.getElementById("show").innerHTML=xmlHttp.getAllResponseHeaders();
        }else{
            alert("Prolem retrieving XML data"+xmlHttp.statusText);
        }
    }
}

Output:

ETag: "4000000030305-3a-522c7fa0e3668" Content-Length: 58 Keep-Alive: timeout=5,max=98 Content-Type: text/plain Last-Modified: Fri,23 Oct 2015 16:19:32 GMT

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读