手记

js创建ajax简单代码,解析XML

var xmlHttp;
if(window.ActiveXObject){
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
    xmlHttp=new XMLHttpRequest();
}

xmlHttp.onreadystatechange=function(){
    var result;
    if(xmlHttp.readyState===4){
        if(xmlHttp.status===200){       
            document.title=xmlHttp.responseXML.getElementsByTagName("response")[0].childNodes[0].nodeValue;

        }
    }

}
xmlHttp.open("get","response.xml");
xmlHttp.send(null);
<?xml version="1.0" encoding="UTF-8"?>
<response>message</response>
1人推荐
随时随地看视频
慕课网APP