学习下Ajax 不会用responseXML   请教下
XML文件<?xml version="1.0" encoding="utf-8" ?>
<People>
  <Name>张三</Name>
  <Age>18</Age>
</People>
<People>
  <Name>李四</Name>
  <Age>19</Age>
</People>
<People>
  <Name>王二</Name>
  <Age>20</Age>
</People>
能给个以responseXML方式读取这个XML的例子吗,感激不尽啊~

解决方案 »

  1.   


    <?xml version="1.0" encoding="utf-8"?>
    <test>
    <People>
    <Name>张三</Name>
    <Age>18</Age>
    </People>
    <People>
    <Name>李四</Name>
    <Age>19</Age>
    </People>
    <People>
    <Name>王二</Name>
    <Age>20</Age>
    </People>
    </test><html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title></title>
    <script type="text/javascript">
    var ajax = (function(){
    function creatXHR(){
    if (window.ActiveXObject) return new window.ActiveXObject('Microsoft.XMLHTTP');
    else if (window.XMLHttpRequest) return new window.XMLHttpRequest();
    else return null;
    }
    return function(url, fn){
    var xhr = creatXHR();
    xhr.open('GET', url, true);
    xhr.onreadystatechange = function(){
    if (xhr.readyState == 4 && xhr.status == 200) {
    fn(xhr);
    }
    }
    xhr.send(null);
    return xhr;
    }
    })(); var test = ajax('xml.xml', function(xhr){
    if (xhr && xhr.responseXML) {
    var names = [], nodes = xhr.responseXML.getElementsByTagName('Name');
    if (nodes) {
    for (var i = 0; i < nodes.length; i++) {
    names.push(nodes[i].childNodes[0].data);
    }
    alert(names.join(', '));
    }
    }
    });
    </script>
    </head>
    <body>
    </body>
    </html>
      

  2.   

    小弟初学者,这段代码过于高深~
         var xmlHttp;
    function CreateXMLHttpRequest()
        {
    if (window.ActiveXObject)
    {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else if (window.XMLHttpRequest)
    {
    xmlHttp = new XMLHttpRequest();
    }
    }function SubGet()
    {
    if (xmlHttp.readyState==4)
    {
    //var node = xmlHttp.responseXML.getElementsByTagName('WebTitle');
    var a = xmlHttp.responseXML.getElementsByTagName('WebTitle');alert(a[0].childNodes[0].data);
    }
    }
    function Fuck()
        {
         CreateXMLHttpRequest();
        if (xmlHttp!=null)
        {
        xmlHttp.open("get","xml.xml",true);
    xmlHttp.onreadystatechange = SubGet;
    xmlHttp.send(null);
        }
        }为何无法获取呢? XML文件  <?xml version="1.0" encoding="utf-8" ?> 
    <Web>
    <Config>
      <WebTitle>标题</WebTitle> 
    </Config>
    </Web>我都快崩溃了~
      

  3.   

    哪位大牛能给个responseXML数据结构也行啊~~
      

  4.   

    貌似JAVASCRIPT是客户端执行吧    我XML在服务器上~
      

  5.   

    已经解决~MIME的问题  ADD: Response.ContentType = "text/xml"  OK!
      

  6.   

    http://download.csdn.net/source/1270171LZ可以看这个,带数据库操作的XML提交数据