Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: weird problem

  1. #1
    New Coder
    Join Date
    May 2005
    Posts
    59
    Thanks
    3
    Thanked 0 Times in 0 Posts

    weird problem

    I'm loving AJAX. Many things are working great and looking very slick. However, I just encountered a strange problem that might actually be JavaScript related... not sure. Since the problem is occuring in my ajax.js library, I'm posting it here.

    I have an xml response that is hanging. Here's a stripped down version of my response:
    Code:
    <response target="same">
      <html>
        <head>
          <SCRIPT type="text/javascript" src="/js/ajax.js"></SCRIPT>
        </head>
        <body>
          <p>test</p>
        </body>
      </html>
    </response>
    This particular response is supposed to just display a simple web page. It's been working in my tests. For the record, I just use a substring on the xmlHttp.responseText (determing the position of the <html> and </html> tags via the indexOf() method) to extract the web page from the response text. That shouldn't be part of the problem... like I said, it's been working in tests.

    However, I add a <SCRIPT> tag (as seen above) and it now hangs. If I remove that tag, it works. Then I stumbled upon this oddity... if I put alerts in my code... presto, it starts working again . Here's the code that is supposed to write the page:

    Code:
    ...
    if(strTarget=="same")
    {
      window.top.document.writeln(gDocType+"\n"+strHtml);
      window.top.document.close();
    }
    ...
    that code hangs. the following code works fine
    Code:
    ...
    if(strTarget=="same")
    {
    alert(1);
      window.top.document.writeln(gDocType+"\n"+strHtml);
    alert(2);
      window.top.document.close();
    alert(3);
    }
    ...
    well, it works fine except for the fact I have to hit "Ok" on three alert boxes. But the page displays fine. If I remove those alerts, the page doesn't display... it just hangs. Or if I remove the <SCRIPT> tag, it displays fine.

    Any ideas?

    Darren

  • #2
    New Coder
    Join Date
    May 2005
    Posts
    59
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Hmmmm... I may have just resolved my issue, but I'm not sure why.

    when I switch to using the function write() instead of writeln(), it starts working again. I thought the only difference between the two was that writeln added an extra new-line character at the end. I'm either wrong on that assumption, or there's some other nuance I'm just not getting. Either way, it seems to work now using write() instead.

    Darren

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,401
    Thanks
    11
    Thanked 595 Times in 575 Posts
    if the script that writes executes while the page is loading, there is a subtle diff between write() and writeln().

    it seems that .write() calls document.open() before it runs.
    .open() clear out the browser enviroment.

    if the script that writes is in "/js/ajax.js", the html tag hangs open while the script is parsed/evaluated.

    .writeln() would thus be dumping inside the middle of the active, open script tag.
    .write() first clears everything out (including the open script tag), and prints from scratch.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •