分享

javascript加载xml文件,在Chrome下不成功!(转)

 _小女子_ 2013-08-26
chrome报错:Uncaught TypeError: Object #<Document> has no method 'load'
Chrome浏览器没有实现XMLdocument.load方法,可以换成XmlHttpRequest

  1. try //Internet Explorer  
  2. {  
  3.  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");  
  4.  xmlDoc.async=false;  
  5.  xmlDoc.load(file);  
  6. }  
  7. catch(e)  
  8. {  
  9.  try //Firefox, Mozilla, Opera, etc.  
  10.  {  
  11.   xmlDoc=document.implementation.createDocument("","",null);  
  12.   xmlDoc.async=false;  
  13.   xmlDoc.load(file);  
  14.  }  
  15.  catch(e)  
  16.  {  
  17.   try //Google Chrome  
  18.   {  
  19.    var xmlhttp = new window.XMLHttpRequest();  
  20.    xmlhttp.open("GET",file,false);  
  21.    xmlhttp.send(null);  
  22.    xmlDoc = xmlhttp.responseXML.documentElement;  
  23.   }  
  24.   catch(e)  
  25.   {  
  26.    error=e.message;  
  27.   }  
  28.  }  




    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多