AJAX获取服务器文件

来源:互联网 发布:域名注册检测工具 编辑:程序博客网 时间:2024/06/06 03:54

index.html

<!DOCTYPE html><html><head>    <title></title></head><body><script type="text/javascript">var xmlHttp=null;function readyStateChangeHandle(){    if(xmlHttp.readyState==4)    {        if(xmlHttp.status==200)        {            var xmlDOM=xmlHttp.responseXML;            var xmlRoot=xmlDOM.documentElement;            try            {                var xmlItem=xmlRoot.getElementsByTagName("item");                alert(xmlItem[0].firstChild.data);            }            catch(e)            {                alert(e.message);            }        }    }}function ajaxRequest(){    if(window.XMLHttpRequest)    {        xmlHttp=new XMLHttpRequest();    }    else if(window.ActiveXObject)    {        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");    }    xmlHttp.onreadystatechange=readyStateChangeHandle;    xmlHttp.open("GET","data.xml",true);    xmlHttp.send(null);}</script><input type="button" di="test" value="test" onclick="ajaxRequest()"></body></html>

data.xml

<?xml version="1.0" encoding="UTF-8"?><root>    <item>woeqwkdqwkd</item></root>
0 0
原创粉丝点击