ajax读取显示xml文件数据
我想利用循环把data.xml文件数据读出
<?xml version="1.0" encoding="GB2312" ?>
<root>
<north>
<id>1</id>
<info>hlj</info>
<time>2001年</time>
<pe>zt</pe>
</north>
<north>
<id>2</id>
<info>heb</info>
<time>2002年</time>
<pe>tyh</pe>
</north>
</root>
我写的AJAX文件为什么不对?
<script type="text/javascript">
var xmlHttp;
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}
function startRequest(){
createXMLHttpRequest();
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open("GET", "data.xml", true);
xmlHttp.send(null);
}
function handleStateChange(){
if(xmlHttp.readyState == 4){
if (xmlHttp.status == 200 || xmlHttp.status == 0){
// 取得XML的DOM对象
var xmlDOM = xmlHttp.responseXML;
// 取得XML文档的根
var root = xmlDOM.documentElement;
try
{
// 取得<info>结果
var out="" ;
var north = root.getElementsByTagName('north');
for (var i = 0; i < north.length; i++)
{
out = out + "<ul><font face='仿宋_GB2312'><span style='font-size: 9pt'>";
out = out + "<li>" + north[i].getElementsByTagName("id").childNodes[0].nodeValue + "</li>";
out = out + "</span></font></ul>";
}
var test = document.getElementById("test");
test.innerHTML = out;
}catch(exception)
{
}
}
}
}
</script>
</head>
<body onload="startRequest();">
<div id="test"><font face="仿宋_GB2312"><span style="font-size: 9pt"></span></font>
</div>
</body>
在线等待,谢谢!