知识学堂
  • ·联系电话:+86.023-75585550
  • ·联系传真:+86.023-75585550
  • ·24小时手机:13896886023
  • ·QQ 咨 询:361652718 513960520
当前位置 > 首页 > 知识学堂 > 网站建设知识
AJAX教程(17):把XML文件显示为HTML表格
更新时间:2011-12-21 | 发布人:本站 | 点击率:453
  {
  alert("Your browser does not support XMLHTTP.");
  }
}

function onResponse()
{
if(xmlhttp.readyState!=4) return;
if(xmlhttp.status!=200)
  {
  alert("Problem retrieving XML data");
  return;
  }

txt="<table border='1'>";
x=xmlhttp.responseXML.documentElement.getElementsByTagName("CD");
for (i=0;i<x.length;i++)
  {
  txt=txt + "<tr>";
  xx=x[i].getElementsByTagName("TITLE");
    {
    try
      {
      txt=txt + "<td>" + xx[0].firstChild.nodeValue + "</td>";
      }
    catch (er)
      {
      txt=txt + "<td> </td>";
      }
    }
  xx=x[i].getElementsByTagName("ARTIST");
    {
    try
      {
      txt=txt + "<td>" + xx[0].firstChild.nodeValue + "</td>";
      }
    catch (er)
      {
      txt=txt + "<td> </td>";
      }
    }
  txt=txt + "</tr>";
  }
txt=txt + "</table>";
document.getElementById('copy').innerHTML=txt;
}

</script>
</head>

<body>
<div id="copy">
<button onclick="loadXMLDoc('/example/xmle/cd_catalog.xml')">Get CD info</button>
</div>
</body>
</html>

分享到: QQ空间 新浪微博 开心网 人人网