转自:http://www.iteye.com/problems/65523
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;
- }
- }
- }
老大,不行啊!能不能照着我贴的代码帮我改下啊!急啊
------------------------------------------------------------------------------------------------------------------
问题补充:
hudingchen 写道
你把代码贴全了阿
我倒,这还不全啊???
------------------------------------------------------------------------------------------------------------------
问题补充:
问题已经解决,原因是:在判断是chrome浏览器的时候没有解析只是去得到了该xml对象
该问题已经关闭: 问题已经解决,原因是:在判断是chrome浏览器的时候没有解析只是去得到了该xml对象
/
//MGQ
改了还是不行。
在Chrome还是不能运行
错误:57
<html>
<head>
<script type="text/javascript">
var xmlDoc;
function loadXML()
{
// 用于 IE 的代码:
/*if (window.ActiveXObject)
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("measure02.xml");
getmessage();
}
// 用于 Mozilla, Firefox, Opera, 等浏览器的代码:
else if (document.implementation &&
document.implementation.createDocument)
{
xmlDoc=document.implementation.createDocument("","",null);
xmlDoc.load("measure02.xml");
xmlDoc.οnlοad=getmessage;
}
else
{
alert('Your browser cannot handle this script');
}
*/
try //Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("measure02.xml");
getmessage();
}
catch(e)
{
try //Firefox, Mozilla, Opera, etc.
{
xmlDoc=document.implementation.createDocument("","",null);
xmlDoc.async=false;
xmlDoc.load("measure02.xml");
xmlDoc.οnlοad=getmessage;
}
catch(e)
{
try //Google Chrome
{
var xmlhttp = new window.XMLHttpRequest();
xmlhttp.open("GET","measure02.xml",false);
xmlhttp.send(null);
xmlDoc = xmlhttp.responseXML.documentElement;
}
catch(e)
{
error=e.message;
}
}
}
setTimeout("loadXML()",100);
}
function getmessage()
{
document.getElementById("ch_one").innerHTML=
xmlDoc.getElementsByTagName("ch_one")[0].childNodes[0].nodeValue;
document.getElementById("ch_two").innerHTML=
xmlDoc.getElementsByTagName("ch_two")[0].childNodes[0].nodeValue;
document.getElementById("ch_three").innerHTML=
xmlDoc.getElementsByTagName("ch_three")[0].childNodes[0].nodeValue;
document.getElementById("ch_four").innerHTML=
xmlDoc.getElementsByTagName("ch_four")[0].childNodes[0].nodeValue;
}
</script>
</head>
<body οnlοad="loadXML()">
<h1>ARM9 远程实时测量技术</h1>
<form name="loandata">
<table border="8">
<tr><td colspan=3> <big> <b> 温度测量点(1-4): </b> </big> </td> </tr>
<tr>
<td>1) </td>
<td> Channel one </td>
<td><span id="ch_one"> </span>℃</td>
</tr>
<tr>
<td>2) </td>
<td> Channel two </td>
<td><span id="ch_two"> </span>℃</td>
</tr>
<tr>
<td>3)</td>
<td> Channel three</td>
<td><span id="ch_three"> </span>℃</td>
</tr>
<tr>
<td>4)</td>
<td> Channel four</td>
<td><span id="ch_four"> </span>℃</td>
</tr>
</table>
</form>
</body>
</html>