我有一个 xml 文件,我想每隔一秒将其内容加载到特定的 html div 中,这是解析 xml 文件的 javascript 部分:
function getEntries() {
if (window.XMLHttpRequest)
req = new XMLHttpRequest();
req.onreadystatechange = handleReq;
req.open("GET", "entries.xml", true);
req.send(null);
}
function handleReq() {
if (req.readyState == 4)
document = req.responseXML;
var states = document.getElementsByTagName("entry");
for (i = 0; i < states.length; i++) {
currentState = states[i];
document.getElementById("LogArea").innerHTML = "<table><tr><td><b>Name:</b></td><td>"
+ currentState.getAttribute("umessage");
+"</td></tr><tr><td><b>Message:</b></td><td>"
+ currentState.getAttribute("uname");
+"</td></tr></table>";
}
}
这是xml文件:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<entries>
<entry umessage="aaaaaaaa" uname="aaaaaaa" />
<entry umessage="Hello everybody" uname="John" />
<entry umessage="Hello everybody" uname="Smith" />
<entry umessage="Hello everybody" uname="Knuth" />
</entries>
这就是html部分:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body bgcolor="yellow" onload='setInterval("getEntries()",1000)'>
<div id="LogArea" align="left">
</div>
</body>
</html>
问题是指定的 div 中没有加载任何内容,并且 firebug 中不存在任何错误