function loadDataXML(sFileName)
{
var sCurrentDocPath=_getPath(document.location.href);
sdocPath=_getFullPath(sCurrentDocPath,sFileName);
if(gbIE5)
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=true;
xmlDoc.onreadystatechange=checkState;
if(document.body!=null)
xmlDoc.load(sdocPath);
}
else if(gbNav6)
{
xmlDoc=document.implementation.createDocument("","",null);
xmlDoc.addEventListener("load",initializeData,false);
xmlDoc.load(sdocPath,"text/xml");
}
}
这段代码在ff和ie是正常的,但是chrome报错了,Uncaught TypeError: Object #<Document> has no method 'load'
求教各位应该怎么写才对啊?
问题补充:dream_hanker 写道
Chrome浏览器没有实现XMLdocument.load方法,你可以换成XmlHttpRequest
下面是一段实例代码
- try //Internet Explorer
- {
- xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
- xmlDoc.async=false;
- xmlDoc.load(file);
- }
- catch(e)
- {
- try //Firefox, Mozilla, Opera, etc.
- {
- xmlDoc=document.implementation.createDocument("","",null);
- xmlDoc.async=false;
- xmlDoc.load(file);
- }
- catch(e)
- {
- try //Google Chrome
- {
- var xmlhttp = new window.XMLHttpRequest();
- xmlhttp.open("GET",file,false);
- xmlhttp.send(null);
- xmlDoc = xmlhttp.responseXML.documentElement;
- }
- catch(e)
- {
- error=e.message;
- }
- }
- }
dream_hanker 写道
Chrome浏览器没有实现XMLdocument.load方法,你可以换成XmlHttpRequest
下面是一段实例代码
- try //Internet Explorer
- {
- xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
- xmlDoc.async=false;
- xmlDoc.load(file);
- }
- catch(e)
- {
- try //Firefox, Mozilla, Opera, etc.
- {
- xmlDoc=document.implementation.createDocument("","",null);
- xmlDoc.async=false;
- xmlDoc.load(file);
- }
- catch(e)
- {
- try //Google Chrome
- {
- var xmlhttp = new window.XMLHttpRequest();
- xmlhttp.open("GET",file,false);
- xmlhttp.send(null);
- xmlDoc = xmlhttp.responseXML.documentElement;
- }
- catch(e)
- {
- error=e.message;
- }
- }
- }