XML loading problem (Firefox and XmlHttpRequest)

Discussion in 'Javascript' started by nick.taylor@gmail.com, Aug 15, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

  2. Hi,

    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
     
    Laurent Bugnion, Aug 16, 2006
    #2
    1. Advertising

  3. Guest

    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, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. gobera

    XMLHttpRequest and Firefox Problem

    gobera, May 3, 2005, in forum: Javascript
    Replies:
    0
    Views:
    84
    gobera
    May 3, 2005
  2. Rich Hephner

    XMLHttpRequest, Firefox and IE inconsistent

    Rich Hephner, May 9, 2005, in forum: Javascript
    Replies:
    4
    Views:
    109
    Rich Hephner
    May 10, 2005
  3. Sergey Surkov

    XMLHttpRequest in FireFox and browser cache

    Sergey Surkov, Jun 4, 2005, in forum: Javascript
    Replies:
    3
    Views:
    151
    Sergey Surkov
    Jun 4, 2005
  4. warteschlange

    XMLHttpRequest in FireFox and cache (Part 2)

    warteschlange, Aug 7, 2005, in forum: Javascript
    Replies:
    2
    Views:
    108
    Martin Honnen
    Aug 7, 2005
  5. kwilder
    Replies:
    39
    Views:
    289
    Randy Webb
    Dec 4, 2005
Loading...

Share This Page