在Javascript中加载xml在firefox中不起作用 [英] Load xml in Javascript doesnt work in firefox
问题描述
以下代码在IE7中运行正常,但FF返回错误:
访问被拒绝以实现属性元素。第一个孩子。在这个
行:
nodes = xmlDoc.documentElement.childNodes;
我的代码:
>
函数CheckNick()
{
nick = document.getElementById(" nick");
nickName = nick。价值;
if(window.ActiveXObject)
{
xmlDoc = new ActiveXObject(" Microsoft.XMLDOM");
xmlDoc.onreadystatechange = function(){
if(xmlDoc.readyState == 4)handleXML()
};
xmlDoc.load(" isNickAvailable.php?nick =" + nickName +"& IEHACK =" +(new
Date())。getTime());
}
else if(document.implementation&&
document.implementation.createDocument)
{
xmlDoc = document.implementation.createDocument("","",null);
xmlDoc.onload = handleXML;
xmlDoc.load(" isNickAvailable.php?nick =" + nickName +"& IEHACK =" +(new
Date())。getTime());
}
else
{
alert(''你的浏览器不能处理这个脚本');
返回;
}
}
函数handleXML()
{
nodes = xmlDoc.documentElement.childNodes;
alert(nodes.item(0).text);
//
alert(xmlDoc.getElementsByTagName(''nick'')。childNod es.firstChild.nodeValue) ;
}
问候
Hush
Hi,
The following code works fine in IE7 but FF returns with an error:
Access denied to achieve the property Element.firstChild. In this
line:
nodes = xmlDoc.documentElement.childNodes;
My code:
function CheckNick()
{
nick = document.getElementById("nick");
nickName = nick.value;
if (window.ActiveXObject)
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.onreadystatechange = function () {
if (xmlDoc.readyState == 4) handleXML()
};
xmlDoc.load("isNickAvailable.php?nick="+nickName+" &IEHACK="+(new
Date()).getTime());
}
else if (document.implementation &&
document.implementation.createDocument)
{
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.onload = handleXML;
xmlDoc.load("isNickAvailable.php?nick="+nickName+" &IEHACK="+(new
Date()).getTime());
}
else
{
alert(''Your browser can\''t handle this script'');
return;
}
}
function handleXML()
{
nodes = xmlDoc.documentElement.childNodes;
alert(nodes.item(0).text);
//
alert(xmlDoc.getElementsByTagName(''nick'').childNod es.firstChild.nodeValue);
}
Regards
Hush
推荐答案
Hush写道:
Hush wrote:
以下代码在IE7中正常工作但FF返回错误:
访问被拒绝实现Element.firstChild属性。在这个
行:
nodes = xmlDoc.documentElement.childNodes;
The following code works fine in IE7 but FF returns with an error:
Access denied to achieve the property Element.firstChild. In this
line:
nodes = xmlDoc.documentElement.childNodes;
在表达式'/ b $ b'中,'firstChild''不会出现错误,该表达式不包含该名称。
It is not likely that you get an error on ''firstChild'' in an expression
that does not contain that name.
函数handleXML()
{
nodes = xmlDoc.documentElement.childNodes;
alert(nodes.item(0).text);
//
alert(xmlDoc.getElementsByTagName(''nick'')。childNod es.firstChild.nodeValue);
function handleXML()
{
nodes = xmlDoc.documentElement.childNodes;
alert(nodes.item(0).text);
//
alert(xmlDoc.getElementsByTagName(''nick'').childNod es.firstChild.nodeValue);
表达式没有意义,getElementsByTagName给出了一个可以索引的
集合,而childNodes给出了一个集合
你也可以索引。
我认为你应该向我们展示你加载的XML并描述你想要读出的元素
然后我们可以帮助编码访问这些元素。
-
Martin Honnen
http://JavaScript.FAQTs.com/
8月7日,14日:41,Martin Honnen< mahotr ... @ yahoo.dewrote:
On 7 Aug., 14:41, Martin Honnen <mahotr...@yahoo.dewrote:
Hush写道:
Hush wrote:
以下代码在IE7中正常工作但FF返回错误:
The following code works fine in IE7 but FF returns with an error:
访问被拒绝以实现属性Element.firstChild。在这个
行:
* nodes = xmlDoc.documentElement.childNodes;
Access denied to achieve the property Element.firstChild. In this
line:
*nodes = xmlDoc.documentElement.childNodes;
在表达式'/ b $ b'中,'firstChild''不会出现错误,该表达式不包含该名称。
It is not likely that you get an error on ''firstChild'' in an expression
that does not contain that name.
对不起,我打错了。当然Access拒绝实现
属性Element.childNodes,而不是firstNode。
Sorry, I typed it wrong. Its of course Access denied to achieve the
property Element.childNodes, and not firstNode.
表达式没有意义,getElementsByTagName给出一个
集合,你可以索引,而childNodes给你一个集合,你可以索引
。
我认为你应该向我们展示XML你加载并描述你要读出的元素
,然后我们可以帮助编码对这些元素的访问。
That expression does not make sense, getElementsByTagName gives a
collection which you can index, and childNodes gives a collection which
you can index too.
I think you should show us the XML you load and describe the elements
you want to read out, then we can help coding the access to those elements.
好的。实际上我只想提取1个数字(1或0)所以我只需要XML中的1
值。我的XML如下:
<?xml version =" 1.0" encoding =" iso-8859-1"?>
< nick>
< isa> 0< / isa>
< / nick>
我正在尝试获取元素的值< isa>
Hush
Ok. Actually I only want to extract 1 number (1 or 0) so I only need 1
value from the XML. My XML is as follows:
<?xml version="1.0" encoding="iso-8859-1"?>
<nick>
<isa>0</isa>
</nick>
I''m trying to get the value of the element <isa>
Hush
Hush写道:
Hush wrote:
好的。实际上我只想提取1个数字(1或0)所以我只需要XML中的1
值。我的XML如下:
<?xml version =" 1.0" encoding =" iso-8859-1"?>
< nick>
< isa> 0< / isa>
< / nick>
我正在尝试获取元素的值< isa>
Ok. Actually I only want to extract 1 number (1 or 0) so I only need 1
value from the XML. My XML is as follows:
<?xml version="1.0" encoding="iso-8859-1"?>
<nick>
<isa>0</isa>
</nick>
I''m trying to get the value of the element <isa>
var isaElements = xmlDoc.getElementsByTagName(''isa'');
if(iseElements.length 0)
{
var isa = isaElements [0];
var n = isa.firstChild.nodeValue;
}
else
{
//处理未找到'isa'元素的案例
}
假设''isa''元素中总有一些文字。
-
Martin Honnen
http://JavaScript.FAQTs.com/
这篇关于在Javascript中加载xml在firefox中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!