在ie浏览器中测试.代码如下:
<script type="text/javascript">
function ac()
{
//指定xml文件的来源地址
var Url="App_Data/indeximg.xml";
//创建XmlDom对象
var cdsales=new ActiveXObject("Microsoft.XMLDOM"); 
//设定XmlDom对象将采取异步调用的方式加载数据
cdsales.async=true; //异步加载
//加载xml文件
cdsales.load(Url);
cdsales.onreadystatechange= new function LoadedSales()
{
    var txt="";
    if(cdsales.readyState==4)
    {
   txt="loaded";
      }
    else{
     txt="Loading.";
    }
    document.write(txt);
}
}
</script> <input id="Button1" type="button" value="button" onclick="ac()" />点击按钮后,一直显示的是"Loading",为什么不能加载xml?谢谢指教!

解决方案 »

  1.   

    if(cdsales.readyState==4)
    {  if(cdsales.status==200){
          txt="loaded";
          }
        else{
        txt="Loading.";
        } 
    }
      

  2.   

    关键是xml文档加载不了.我要调用xml里面的数据,现在用不了
      

  3.   

    js加载xml,ie 与ff的加载方式不同
    你用这个方法试试loadXml = function(fileRoute){
    xmlDoc=null;
      if (window.ActiveXObject){
    xmlDoc = new ActiveXObject('Msxml2.DOMDocument');
    xmlDoc.async=false;
    xmlDoc.load(fileRoute);
    }else if (document.implementation && document.implementation.createDocument){
    var xHRO = new window.XMLHttpRequest(); // 兼容 Chrome
    xHRO.open('GET',fileRoute,false);
    xHRO.send(null); 
    xmlDoc = xHRO.responseXML; 
    }else{
    xmlDoc=null;
    }
    return xmlDoc;
    }
      

  4.   

    该方法返回的 xmlDocument object 
      

  5.   

    cdsales.onreadystatechange= new function LoadedSales() 

        var txt=""; 
        if(cdsales.readyState==4) 
        { 
      txt="loaded"; 
          } 
        else{ 
        txt="Loading."; 
        } 
        //document.write(txt); ///不要在函数中使用此语句,会导致当前页面的内容会被覆盖,改用append方法
    document.body.appendChild(document.createTextNode(txt));
      

  6.   

    没有效果,xmldoc为null.txt输出为""