...

weird problem

Darren
09-06-2007, 09:53 PM
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:
<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 :confused: . Here's the code that is supposed to write the page:

...
if(strTarget=="same")
{
window.top.document.writeln(gDocType+"\n"+strHtml);
window.top.document.close();
}
...that code hangs. the following code works fine
...
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

Darren
09-06-2007, 10:42 PM
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

rnd me
09-09-2007, 06:51 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum