如题,在网上找了解决方案,但是在浏览器上都打不开,浏览器上显示的是空白啊。<html><body> <script type="text/javascript"> var xmlhttp = new XMLHttpRequest(); xmlhttp.open("GET","123.xml",false);xmlhttp.send(null);xmlDoc=xmlhttp.responseXML; document.write("<table border='1'>");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></tr>"); }document.write("</table>");</script> </body></html>
document.write(x.item(i).getElementsByTagName("ARTIST").item(0).text;);
哥哥能解释下这行啥意思么?你指望js用XMLHttpRequest去读客户端本地xml文件?
你这些代码本来的用意是什么能解释下么
;(function(w){
var xml = function(u){
var x = w.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
x.open('GET', u, false);
x.send(null);
x = x.responseXML;
return x;
};
w.Cme = w.Cme ? w.Cme : {};
w.Cme.xml = xml;
})(window);
var xml = Cme.xml('test.xml');
alert(xml.documentElement.getElementsByTagName('name')[0].firstChild.nodeValue);
</script>test.xml<?xml version="1.0" encoding="gb2312"?>
<root>
<item>
<name>Jam Green</name>
</item>
<item>
<name>Tom Blue</name>
</item>
</root>
需要配置本地服务器,以http://127.0.0.1/test.html 这样才能运行。