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

XML loading problem (Firefox and XmlHttpRequest)

P: n/a
Hi,
I've been trying for weeks to figure out this problem. I'm developing a
simple Javascript app that loads an XML file from a server, parses the
contents, and displays them. But I am encountering a very mysterious
bug that I can't seem to get rid of.

When loading the page in Internet Explorer, everything works, and in
Firefox it works except for one problem: the page never stops loading.
The script runs and everything parses but it just keeps spinning.

The XML file I am loading is on the same server (and is in the same
directory) as the Javascript file itself. Here is the code:
function importXML()
{
if (document.implementation && document.implementation.createDocument)
{
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.onload = parseTOC;
}
else if (window.ActiveXObject)
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.onreadystatechange = function () {
if (xmlDoc.readyState == 4) parseTOC()
};
}
else
{
alert('Your browser can\'t handle this script');
return;
}
xmlDoc.load("filename.xml");
}

function parseTOC() {
document.write("parsing....<br/>");
createTOC(xmlDoc.documentElement, 0); // My function -- it works
properly
document.write("<br/>parser terminated<br/>");
}

importXML();

I should mention that I've tried every variant on this code you can
name, including using prototype.js for the AJAX request and a few
freeware XML importing libs. But I can't get rid of the problem. Even
if I comment out the "createTOC" line, the same thing happens...
Firefox never stops loading. (I'm on Windows)

My suspicion is that there's an HTTP header I need to send, but I can't
think of what it would be. The server is serving "text/xml" and I've
tried passing the "Connection: close" header, but nothing happened.

I would greatly appreciate help with this frustrating problem...
Nick

Aug 15 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

ni*********@gmail.com wrote:
Hi,
I've been trying for weeks to figure out this problem. I'm developing a
simple Javascript app that loads an XML file from a server, parses the
contents, and displays them. But I am encountering a very mysterious
bug that I can't seem to get rid of.

When loading the page in Internet Explorer, everything works, and in
Firefox it works except for one problem: the page never stops loading.
The script runs and everything parses but it just keeps spinning.
<snip>
function parseTOC() {
document.write("parsing....<br/>");
createTOC(xmlDoc.documentElement, 0); // My function -- it works
properly
document.write("<br/>parser terminated<br/>");
}
<snip>

Try closing the document when you're done writing to it,

function parseTOC() {
document.write("parsing....<br/>");
createTOC(xmlDoc.documentElement, 0);
document.write("<br/>parser terminated<br/>");
document.close();
}

Note that using document.write to do this kind of things is questionable
IMHO. I would rather use DIVs with IDs and then use DOM Level 2 methods
to get the specific nodes and write to them. This way has the advantage
of working even when the document is fully loaded, however it won't work
in old (Netscape 4) or thin (PDAs) browsers.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Aug 16 '06 #2

P: n/a
Laurent Bugnion wrote:
Hi,

Try closing the document when you're done writing to it,

function parseTOC() {
document.write("parsing....<br/>");
createTOC(xmlDoc.documentElement, 0);
document.write("<br/>parser terminated<br/>");
document.close();
}

Note that using document.write to do this kind of things is questionable
IMHO. I would rather use DIVs with IDs and then use DOM Level 2 methods
to get the specific nodes and write to them. This way has the advantage
of working even when the document is fully loaded, however it won't work
in old (Netscape 4) or thin (PDAs) browsers.

I knew it'd be something simple! That seems to work, although the
document.write statements are just debugging statements that I will
remove once everything is working.
Thanks for your help,
Nick

Aug 16 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.