W3CSchool的教程中提供过一个loadXMLDoc函数:
function loadXMLDoc(url) {
var xmlDoc;
try{
xmlDoc
=new ActiveXObject("Microsoft.XMLDOM");
}
catch(e){
try{
xmlDoc
=document.implementation.createDocument("","",null);
}
catch(e){
alert(e.message);
return;
}
}
xmlDoc.async
=false;
xmlDoc.load(url);
return xmlDoc;
}

不过在谷歌浏览器中会出现如下错误:
Object #<a Document> has no method 'load'
所以为了适应谷歌浏览器只能用XMLHttpRequest对像再responseXML得到XML
修改后的loadXMLDoc函数如下:
function loadXMLDoc(url) {
var xmlDoc;
try{
xmlDoc
=new ActiveXObject("Microsoft.XMLDOM");
}
catch(e){
try{
var oXmlHttp = new XMLHttpRequest() ;
oXmlHttp.open(
"GET", url, false ) ;
oXmlHttp.send(
null) ;
return oXmlHttp.responseXML;
}
catch(e){
return;
}
}
xmlDoc.async
=false;
xmlDoc.load(url);
return xmlDoc;
}

相关文章:

  • 2021-05-21
  • 2021-10-20
  • 2021-06-01
  • 2021-10-20
  • 2021-12-26
  • 2021-11-27
  • 2021-07-29
猜你喜欢
  • 2021-12-12
  • 2021-12-30
  • 2021-09-08
  • 2021-09-26
  • 2021-12-01
  • 2022-12-23
相关资源
相似解决方案