请教大侠 xmlhttp.responseXML.documentElement返回为unll问题
测试 1.asp和1.xml页面的内容:
<?xml version="1.0" encoding="utf-8"?>
<note>
<t1>
<bt>您好!1</bt>
<nr>内容1</nr>
<url>http://dotnet1.aspx.cc/</url>
</t1>
<t1>
<bt>您好!2</bt>
<nr>内容2</nr>
<url>http://dotnet2.aspx.cc/</url>
</t1>
</note>
以下代码能获取到1.xml返回的内容,获取1.asp返回内容是unll 。
请教大侠指导 获取1.asp文件的返回内容,为感!
<script type="text/javascript">
var xmlDoc = null, xmlhttp = null;
function loadXML() {
xmlhttp = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHttp");
if (xmlhttp == null) {
alert("你的浏览器不支持 XMLHttpRequest");
return;
}
//var url = "1.xml";
var url = "1.asp";
xmlhttp.open("GET", url, true);
xmlhttp.setRequestHeader("Content-Type", "text/xml;charset=utf-8");
xmlhttp.onreadystatechange = getmessage;
xmlhttp.send(null);
}
function getmessage() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
xmlDoc = xmlhttp.responseXML.documentElement;
if (xmlDoc == null) {
alert(xmlDoc);
return;
}
var nodes = xmlDoc.getElementsByTagName("t1")
tb = document.getElementById("table_note");
tbody = document.createElement("tbody")
for (i = 0; i < nodes.length; i++)
{
tr = document.createElement("tr")
td = document.createElement("td")
td.innerHTML = nodes[i].getElementsByTagName("bt")[0].childNodes[0].nodeValue
tr.appendChild(td)
td = document.createElement("td")
td.innerHTML = nodes[i].getElementsByTagName("nr")[0].childNodes[0].nodeValue
tr.appendChild(td)
td = document.createElement("td")
url = nodes[i].getElementsByTagName("url")[0].childNodes[0].nodeValue;
td.innerHTML = "<a href='" + url + "'>" + url + "</a>"
tr.appendChild(td)
tbody.appendChild(tr)
}
tb.appendChild(tbody)
}
}
</script>
</head>
<body onLoad="loadXML()">
<table cellpadding="6" id="table_note">
<tr>
<td>标题</td>
<td>内容</td>
<td>网址</td>
</tr>
</table>
</body>
</html>