我编写了一个简单的代码来使用 XML 文件。如果我使用以 .xml 结尾的链接,它可以正常工作。但是,当我使用http://www.tbl.org.tr/xml.asp?Lig=Beko&Eylem=PD&sezon=2013-2014更改链接时,它显示了任何内容。
我的代码如下。
我怎么解决这个问题?
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body>
<script>
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET", "http://www.tbl.org.tr/xml.asp?Lig=Beko&Eylem=PD&sezon=2013-2014", false);
xmlhttp.send();
xmlDoc = xmlhttp.responseXML;
document.write("<table width='350' cellpadding='5'>");
var x = xmlDoc.getElementsByTagName("Siralama");
document.write("<tr><td width='20'>");
document.write("Sıra");
document.write("</td><td width='290'>");
document.write("Takım");
document.write("</td><td width='20'>");
document.write("O");
document.write("</td><td width='20'>");
document.write("G");
for ( i = 0; i < 8; i++) {
document.write("<tr><td width='20'>");
document.write(x[i].getAttribute('Sira'));
document.write("</td><td width='290'>");
var y = x[i].getAttribute('Takim');
if (y.length == 15)
document.write("<font color=red><b>" + x[i].getAttribute('Takim') + "</b></font>");
else
document.write(x[i].getAttribute('Takim'));
document.write("</td><td width='20'>");
document.write(x[i].getAttribute('O'));
document.write("</td><td width='20'>");
document.write(x[i].getAttribute('G'));
document.write("</td></tr>");
}
document.write("</table>");
</script>
</body>