XML loading problem (Firefox and XmlHttpRequest)

nick.taylor

Usenet Archive
Joined
Aug 15, 2006
Messages
2
Reaction score
0
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
 

Laurent Bugnion

Usenet Archive
Joined
Aug 20, 2002
Messages
771
Reaction score
0
Hi,

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.

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
 

nick.taylor

Usenet Archive
Joined
Aug 15, 2006
Messages
2
Reaction score
0
Laurent said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,246
Members
248,133
Latest member
DujonT

Latest Threads

Top