zoukankan      html  css  js  c++  java
  • AJAX-responseXML 属性

    如果来自服务器的响应是 XML,而且需要作为 XML 对象进行解析,需要使用 responseXML 属性

    cd_catalog.xml:

    <CATALOG><CD><TITLE>Empire Burlesque</TITLE><ARTIST>Bob Dylan</ARTIST><COUNTRY>USA</COUNTRY><COMPANY>Columbia</COMPANY><PRICE>10.90</PRICE><YEAR>1985</YEAR></CD><CD><TITLE>Hide your heart</TITLE><ARTIST>Bonnie Tyler</ARTIST><COUNTRY>UK</COUNTRY><COMPANY>CBS Records</COMPANY><PRICE>9.90</PRICE><YEAR>1988</YEAR></CD><CD><TITLE>Greatest Hits</TITLE><ARTIST>Dolly Parton</ARTIST><COUNTRY>USA</COUNTRY><COMPANY>RCA</COMPANY><PRICE>9.90</PRICE><YEAR>1982</YEAR></CD></CATALOG>

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <script>
    function loadXMLDoc()
    {
      var xmlhttp;
      var txt,x,i;
      if (window.XMLHttpRequest)
      {
        // IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
        xmlhttp=new XMLHttpRequest();
      }
      else
      {
        // IE6, IE5 浏览器执行代码
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      xmlhttp.onreadystatechange=function()
      {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
          xmlDoc=xmlhttp.responseXML;
          txt="";
          x=xmlDoc.getElementsByTagName("TITLE");
          for (i=0;i<x.length;i++)
          {
            txt=txt + x[i].childNodes[0].nodeValue + "<br>";
          }
          document.getElementById("myDiv").innerHTML=txt;
        }
      }
      xmlhttp.open("GET","cd_catalog.xml",true);
      xmlhttp.send();
    }
    </script>
    </head>

    <body>

    <h2>我收藏的 CD :</h2>
    <div id="myDiv"></div>
    <button type="button" onclick="loadXMLDoc()">获取我的 CD</button>
     
    </body>
    </html>

    结果:

    我收藏的 CD :

    Empire Burlesque
    Hide your heart
    Greatest Hits
    Still got the blues
    Eros
    One night only
    Sylvias Mother
    Maggie May
    Romanza
    When a man loves a woman
    Black angel
    1999 Grammy Nominees

  • 相关阅读:
    资源: StaticResource, ThemeResource
    资源: CustomResource, ResourceDictionary, 加载外部的 ResourceDictionary 文件
    绘图: Shape, Path
    绘图: Stroke, Brush
    动画: 线性动画, 关键帧动画
    动画: 缓动动画
    动画: ThemeAnimation(主题动画)
    动画: ThemeTransition(过渡效果)
    绑定: 与 Element 绑定, 与 Indexer 绑定, TargetNullValue, FallbackValue
    BeautifulSoup在Windows下安装(running 2to3)
  • 原文地址:https://www.cnblogs.com/soyo/p/6860200.html
Copyright © 2011-2022 走看看