我想弄清楚如何從未在我自己的網站上託管的XML文件中提取數據。我完全不熟悉這個,所以我不知道我要出錯的地方。我可以輕鬆地從我自己的站點獲取這些數據。任何幫助將不勝感激,謝謝!從外部網站拉取XML數據
<script type="text/javascript">
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
url = "http://elcu.herobo.com/testarea/include/cd_catalog.xml"
xmlhttp.open("GET",url,false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
document.write("<table border='0' cellpadding='1' cellspacing='1' width'90%' id='1' class='tablesorter'><thead><tr> <th>Artist</th> <th>Title</th> <th>Country</th></thead><tbody>");
var x=xmlDoc.getElementsByTagName("CD");
for (i=0;i<x.length;i++)
{
document.write("<tr><td>");
document.write(x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("COUNTRY")[0].childNodes[0].nodeValue);
document.write("</td></tr>");
}
document.write("</tbody></table>");