By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,696 Members | 2,182 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,696 IT Pros & Developers. It's quick & easy.

Load xml in Javascript doesnt work in firefox

P: n/a
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
Aug 7 '08 #1
Share this Question
Share on Google+
20 Replies


P: n/a
Hush wrote:
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;
It is not likely that you get an error on 'firstChild' in an expression
that does not contain that name.

function handleXML()
{
nodes = xmlDoc.documentElement.childNodes;
alert(nodes.item(0).text);
//
alert(xmlDoc.getElementsByTagName('nick').childNod es.firstChild.nodeValue);
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.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 7 '08 #2

P: n/a
On 7 Aug., 14:41, Martin Honnen <mahotr...@yahoo.dewrote:
Hush wrote:
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;

It is not likely that you get an error on 'firstChild' in an expression
that does not contain that name.
Sorry, I typed it wrong. Its of course Access denied to achieve the
property Element.childNodes, and not firstNode.
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.
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

Aug 7 '08 #3

P: n/a
Hush wrote:
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
{
// handle case that 'isa' element was not found
}

That assumes that the 'isa' element always has some text in it.


--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 7 '08 #4

P: n/a
>
* *var isaElements = xmlDoc.getElementsByTagName('isa');
* *if (iseElements.length 0)
* *{
* * *var isa = isaElements[0];
* * *var n = isa.firstChild.nodeValue;
* *}
* *else
* *{
* * *// handle case that 'isa' element was not found
* *}
I'm stil getting the error for firstChild in this line:
var n = isa.firstChild.nodeValue;

I tested in IE. And it worked nicely...
Aug 7 '08 #5

P: n/a
Hush wrote:
I'm stil getting the error for firstChild in this line:
var n = isa.firstChild.nodeValue;
Can you post the exact error message? Your first post said "access
denied" which sounds more like a security exception. I am not sure why
you would get that, if you tried to load the XML from a different origin
then I would expect the load call to already throw an exception.
If you have a URL we can visit then post that too.

Does that problem occur with Firefox 3? Have you checked whether it also
occurs with Firefox 2?

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 7 '08 #6

P: n/a
On 7 Aug., 18:14, Martin Honnen <mahotr...@yahoo.dewrote:
Hush wrote:
*I'm stil getting the error for firstChild in this line:
var n = isa.firstChild.nodeValue;

Can you post the exact error message? Your first post said "access
denied" which sounds more like a security exception. I am not sure why
you would get that, if you tried to load the XML from a different origin
then I would expect the load call to already throw an exception.
If you have a URL we can visit then post that too.

Does that problem occur with Firefox 3? Have you checked whether it also
occurs with Firefox 2?

--

* * * * Martin Honnen
* * * *http://JavaScript.FAQTs.com/
I translated the error from a danish version of firebug. I'm using
FF3, but when I come to think of it I had a similar error a while ago
with the same error. This was in an unchanged code, but after the
upgrade to FF3, so this could definately be the cause. I havent tested
in FF2. ( I will try that now)

URL:
http://www.sporturn.com/new/popuppages/new_profile.php
Aug 7 '08 #7

P: n/a
Does that problem occur with Firefox 3? Have you checked whether it also
occurs with Firefox 2?
It works in FF2. So the problem is in FF3 :|

Is there a fix??

Aug 7 '08 #8

P: n/a
Hush wrote:
>>Does that problem occur with Firefox 3? Have you checked whether it also
occurs with Firefox 2?

It works in FF2. So the problem is in FF3 :|
Oddly enough I have just tested with Mozilla/5.0 (Windows; U; Windows NT
5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1 and entered some
characters into the "nick" field and I don't get any error in the error
console, instead each time an alert dialog with '1' is displayed.
Is there a fix??
I am still not sure why you get that error and I can't reproduce it.
As a workaround you might want to try to load the XML with
XMLHttpRequest instead of xmlDoc.load(), perhaps that avoids the problem.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 7 '08 #9

P: n/a
Hush wrote:
>>Does that problem occur with Firefox 3? Have you checked whether it also
occurs with Firefox 2?

It works in FF2. So the problem is in FF3 :|
True, but that does not necessarily mean that the problem *is* Fx 3.
For example, Firebug for Fx 3 is still beta.
Is there a fix??
For a start, you could try not to mix standards compliant and proprietary
features, which would be a good idea in any case.
PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Aug 7 '08 #10

P: n/a
On 7 Aug., 19:10, Martin Honnen <mahotr...@yahoo.dewrote:
Hush wrote:
>Does that problem occur with Firefox 3? Have you checked whether it also
occurs with Firefox 2?
It works in FF2. So the problem is in FF3 :|

Oddly enough I have just tested with Mozilla/5.0 (Windows; U; Windows NT
5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1 and entered some
characters into the "nick" field and I don't get any error in the error
console, instead each time an alert dialog with '1' is displayed.
An Alert should be displayed if it works.
The error message is in Firebug only, and its still a beta release.
But that still doesnt change the fact that it doesnt work in FF3...:(
I am still not sure why you get that error and I can't reproduce it.
As a workaround you might want to try to load the XML with
XMLHttpRequest instead of xmlDoc.load(), perhaps that avoids the problem.
I'm new in js, so can you give me an example?
Aug 7 '08 #11

P: n/a
True, but that does not necessarily mean that the problem *is* Fx 3.
For example, Firebug for Fx 3 is still beta.
Yes. You are right. But its still pretty annoying that there has to be
a difference:D
For a start, you could try not to mix standards compliant and proprietary
features, which would be a good idea in any case.
I'm sorry, I didnt understand a word of that..... (I'm new in JS)
Please bare with me....
Aug 7 '08 #12

P: n/a
Hush wrote:
An Alert should be displayed if it works.
The error message is in Firebug only, and its still a beta release.
But that still doesnt change the fact that it doesnt work in FF3...:(
Then disable Firebug and check whether it works then. I don't have
Firebug for FF 3 and it works for me.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 8 '08 #13

P: n/a
Then disable Firebug and check whether it works then. I don't have
Firebug for FF 3 and it works for me.
Interesting... After I disabled it, the code goes to the 'else' in
this code:

if (isaElements.length 0)
{

var isa = isaElements[0];
var n = isa.firstChild.nodeValue;

}
else
{
alert("isa element not found");// handle case that 'isa' element
was not found
}

Which has to mean that this line doesnt work (I guess):
var isaElements = xmlDoc.getElementsByTagName('isa');
Aug 8 '08 #14

P: n/a
* *else
* *{
* * *alert("isa element not found");// handle case that 'isa' element
was not found
* *}
I commented the line above out, and now it seems to work :| I dont
understand...........

http://www.sporturn.com/new/popuppages/new_profile.php

Does this make any sense to you?
Aug 8 '08 #15

P: n/a
Hush wrote:
> else
{
alert("isa element not found");// handle case that 'isa' element
was not found
}

I commented the line above out, and now it seems to work :| I dont
understand...........

http://www.sporturn.com/new/popuppages/new_profile.php

Does this make any sense to you?
No, not really, if you uncomment an else branch of an if/else statement
then it should not change the result of evaluating the condition.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 8 '08 #16

P: n/a
On Aug 8, 5:04*am, Hush <ke...@skummer.comwrote:
* *else
* *{
* * *alert("isa element not found");// handle case that 'isa' element
was not found
* *}

I commented the line above out, and now it seems to work :| I dont
understand...........

http://www.sporturn.com/new/popuppages/new_profile.php

Does this make any sense to you?
I had the exact error - and it seems to be caused by Firebug. I
upgraded to FF3 yesterday, and my scripting worked, then installed
the
new version of firebug, and the scripts calling XML failed with the
permission error.

Unistall Firebug, and test.
Aug 8 '08 #17

P: n/a
On 8 Aug., 19:10, kerry.gei...@dreamworks.com wrote:
On Aug 8, 5:04*am, Hush <ke...@skummer.comwrote:
* *else
* *{
* * *alert("isa element not found");// handle case that 'isa' element
was not found
* *}
I commented the line above out, and now it seems to work :| I dont
understand...........
http://www.sporturn.com/new/popuppages/new_profile.php
Does this make any sense to you?

*I had the exact error - and it seems to be caused by Firebug. I
*upgraded to FF3 yesterday, and my scripting worked, then installed
the
*new version of firebug, and the scripts calling XML failed with the
*permission error.

*Unistall Firebug, and test.
Yup. thats the solution. Everything works fine here now. (What an
annoying mistake !!)

Thank you all for the support:)
Aug 8 '08 #18

P: n/a
Hush wrote:
On 8 Aug., 19:10, kerry.gei...@dreamworks.com wrote:
>On Aug 8, 5:04 am, Hush <ke...@skummer.comwrote:
>>> else
{
alert("isa element not found");// handle case that 'isa' element
was not found
}
I commented the line above out, and now it seems to work :| I dont
understand...........
http://www.sporturn.com/new/popuppages/new_profile.php
Does this make any sense to you?
I had the exact error - and it seems to be caused by Firebug. I
upgraded to FF3 yesterday, and my scripting worked, then installed
the new version of firebug, and the scripts calling XML failed with the
permission error.

Unistall Firebug, and test.

Yup. thats the solution. Everything works fine here now. (What an
annoying mistake !!)
It would appear that you have been using a substandard Firebug version or
one that is not suited for Fx 3, because I have Firebug 1.2.0b7 installed
on top of Firefox 3.0.1 and it WFM as it did before.
PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Aug 9 '08 #19

P: n/a
It would appear that you have been using a substandard Firebug version or
one that is not suited for Fx 3, because I have Firebug 1.2.0b7 installed
on top of Firefox 3.0.1 and it WFM as it did before.
I user Firebug 1.2.0b7, and after deactivating, the problem
disappeared.
Aug 9 '08 #20

P: n/a
Hush wrote:
>It would appear that you have been using a substandard Firebug version or
one that is not suited for Fx 3, because I have Firebug 1.2.0b7 installed
on top of Firefox 3.0.1 and it WFM as it did before.

I user Firebug 1.2.0b7, and after deactivating, the problem
disappeared.
Then there must be at least one other difference between our test environments.
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Aug 9 '08 #21

This discussion thread is closed

Replies have been disabled for this discussion.