javascript加载xml,在chrome下失败的解决办法
原来的写法:
this.loadxml = function(xml) { var xmlDoc; if (window.ActiveXObject) { xmlDoc = new ActiveXObject('Microsoft.XMLDOM'); xmlDoc.async = false; xmlDoc.load(xml); } else if (document.implementation && document.implementation.createDocument) { xmlDoc = document.implementation.createDocument('', '', null); xmlDoc.async = false; xmlDoc.load(xml); } else { return null; } return xmlDoc; };
修改后的写法:
this.loadxml = function(xml) { var xmlDoc; if (window.ActiveXObject) { xmlDoc = new ActiveXObject('Microsoft.XMLDOM'); xmlDoc.async = false; xmlDoc.load(xml); } else if (document.implementation && document.implementation.createDocument) { try{ xmlDoc = document.implementation.createDocument('', '', null); xmlDoc.async = false; xmlDoc.load(xml); } catch(e){ var xmlhttp = new window.XMLHttpRequest(); xmlhttp.open("GET",xml,false); xmlhttp.send(null); xmlDoc = xmlhttp.responseXML.documentElement; } } else { return null; } return xmlDoc; };
相关推荐
与卿画眉共浮生 2020-10-14
xiyang 2020-08-21
baijinswpu 2020-07-29
leonranri 2020-07-26
zhongliwen 2020-07-05
麋鹿麋鹿迷了路 2020-07-05
zengyu00 2020-07-05
XGQ 2020-07-04
CoderBoy 2020-06-28
whbing 2020-06-28
绝望的乐园 2020-06-27
wellfly 2020-06-26
菇星獨行 2020-06-25
草原孤狼 2020-06-25
坚持着执着 2020-06-16
wcqwcq 2020-06-14
yuanye0 2020-06-14
zhongliwen 2020-06-13
MrFuWen 2020-06-09