这样一段代码:function GetXmlObject(xmlFileName)
{
    var xmlDoc;
    if(window.ActiveXObject)
    {
          xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
    }
    else
    {
          var xmlDoc=document.implementation.createDocument("", "", null);
    }
    xmlDoc.async=false;
    xmlDoc.validateOnParse=false;
    xmlDoc.load(xmlFileName);
    return xmlDoc;
}这样获得的XML在IE中解析没有任何问题,但在FireFox中时而可以解析,时而不行,后来在FireBug中调试发现就在xmlDoc.load(xmlFileName);的时候有时能load到xml文档,有时无法load到,不知道有没有哪位大侠遇到过此类问题,有无解决方法?

解决方案 »

  1.   

    <html>
    <body>
    <script type="text/javascript">
    try //Internet Explorer
      {
      xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
      }
    catch(e)
      {
      try //Firefox, Mozilla, Opera, etc.
        {
        xmlDoc=document.implementation.createDocument("","",null);
        }
      catch(e) {alert(e.message)}
      }
    try 
      {
      xmlDoc.async=false;
      //加载XML文件 
      xmlDoc.load("books.xml");
      document.write("xmlDoc is loaded, ready for use");
      }
    catch(e) {alert(e.message)}
    </script>
    </body>
    </html>