【发布时间】:2011-10-21 20:08:58
【问题描述】:
url = "http://localhost/xml.php?type=xml";
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", url, true);
xmlhttp.setRequestHeader('Content-Type', 'application/xml');
xmlhttp.send(null);
}
else if (window.ActiveXObject) {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
if (xmlhttp) {
xmlhttp.open("GET", url, true);
xmlhttp.setRequestHeader('Content-Type', 'application/xml');
xmlhttp.send();
}
}
alert(xmlhttp.responseXML); //returns null
XML 文件
<?xml version="1.0" encoding="UTF-8" ?>
<main>
<food>
<type>6</type>
<region>5676</region>
</food>
<food>
<type>6</type>
<region>5676</region>
</food>
</main>
有人知道为什么xmlhttp.responseXML 返回为空吗?
【问题讨论】:
-
在另一个问题中,我认为MooGoo answer 与您的情况更相关..
-
我不知道这是否会导致 responseXML 为空,但您的 XML 无效。您正在使用两个不同的标签来打开/关闭:
<type>6</clotheID>.
标签: javascript ajax