w3C回答不适用于在IE中加载XML

时间:2011-07-21 04:40:49

标签: javascript html xml

我想在IE 7/8中加载XML文件,然后从w3c中搜索答案。我找到了答案,以下代码,但是当我使用javascript执行此操作时,它会显示“访问被拒绝”#39;错误到我的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>

1 个答案:

答案 0 :(得分:1)

旧版本的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;
}