我想在IE 7/8中加载XML文件,我从w3c搜索答案。我找到了答案,下面的代码,但是当我使用javascript这样做时,它显示"访问被拒绝"错误到我的js文件。有人能帮我吗?
w3c link: Example
<script type="text/javascript">
function loadXML(location) {
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else // for IE 5/6
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",location,false); // error in here, even I type the link here, also not work
xhttp.send();
xmlDoc=xhttp.responseXML;
}
</script>
旧版本的IE不支持responseXML,你可以这样做:
if (window.ActiveXObject) {
var response = xhttp.responseText;
var XMLdoc = new ActiveXObject("Microsoft.XMLDOM");
XMLdoc.loadXML(http_request.responseText);
}else {
var XMLdoc = http_request.responseXML;
}