AJAX "crashes" IE on close of Window.

S

Sommer.pde

It took me some time to find out when and why this happens.

When the window of Internet Explorer is closed with an AJAX call still
pending, something funny happens. Do it twice, and you will have to
restart the browser.

Here a little sample: http://truefriendz.de/iedos

The script on this site will open 5 test-windows one at a time.

The test-windows will issue an AJAX-Call. This call would only be
answered after 10 seconds, but the windows will be closed before
the answer arrives. (This is not a question of the window.close().
The same would happen if the close is issued by a user closing the
window)

Using IE6/w2k and IE7/vista (and assumedly other versions of IE)
the 3rd and following windows will appear without content. FireFox
performs perfectly well.

I found a workarround, which I regard as clumsy.

<body .... onAbort="cleanup();" onUnload="cleanup();">
function cleanup() { xmlHttp.abort();}

Demonstration here: http://truefriendz.de/iedos2

My findings so far: When a window with a pending AJAX-request
ActiveXObject("Microsoft.XMLHTTP") is closed, a TCP-socket remains
eternally in state close_wait. Check with netstat.

(It seems perfectly normal that sockets enter the state close_wait
(although if I understand the documents correctly this state should
only be entered by SERVERS),
and it seems that sockets can (normally) be reused succesfully from
this state. In "normal operation" such socktes do disappear after a
certain time)

My thoughts: Due to the fact that this Socket is still existing, IE
does
reuse it, but it does not work properly. These Sockets seem
to be damaged somehow.

Funny enough, I did not find any mention of this problem on the web.

Anyone, who can suggest a better, more elegant way to handle this?

Sorry for any mistakes, I did my very best, but I'm not a native
speaker.
 
L

-Lost

It took me some time to find out when and why this happens.

When the window of Internet Explorer is closed with an AJAX call still
pending, something funny happens. Do it twice, and you will have to
restart the browser.

Here a little sample: http://truefriendz.de/iedos

The script on this site will open 5 test-windows one at a time.

Really? In my Internet Explorer 6 it merely says it is opening and
closing windows, but it does not open or close anything.

I do however get:

Line: 39
Char: 2
Error: Object doesn't support this property or method
Code: 0
URL: http://truefriendz.de/iedos/

....5 times.

<snip>
 
S

Sommer.pde

Really? In my Internet Explorer 6 it merely says it is opening and
closing windows, but it does not open or close anything.

Well, it should, and it *does* on my computer. :)

Thank for giving it a try. The site where this script is hosted is
not mine, so I can do nothing about it *at this site*. But I
made a modified copy here:

http://sommerb.so.funpic.de/ajax/iedos.html

Perhaps this one wil do the Trick. Sorry, this site is not cpmpletely
ad-free, but this was the only PHP-enabled web space I could find
in short time.

I would be very grateful if anybody would have a look at this. I'm
completely at loss, since I found out that even the version *with*
calls to abort() of the AJAX does indeed throw a exception in
FireFox.

TIA
 
S

Sommer.pde

Just to give more informations:

<head>
var xmlHttp;

function ajax_call(){

//create AJAX.object
xmlHttp = new ActiveXObject(versions[idx]);

// Define onreadystatechange and issue call to very slow site
xmlHttp.open('GET', 'response-10s.php', true);
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
alert(xmlHttp.responseText);
}
};
xmlHttp.send(null);
}

function cleanup() {
if (xmlHttp) {xmlHttp.abort()}
}
</head>

<body onLoad="ajax_call();" onAbort="cleanup();" onUnload="cleanup();"....

Without cleanup() this will do damage to Internet-Explorer
(sockets permanently in state close_wait) if the window
is closed with the AJAX still waiting for the response.

Obviously the Ajax doesn't "like" to go into non-existence
without a pending call beeing aborted.

I have very foggy ideas about an Ajax-object that enlists
itself for cleanup...

Somehow to add this cleanup into a chain of operations that are
done automatically on close of the window. I examined some
AJAX-Libraries, but found nothing like that in any of them.
 
L

-Lost

I would be very grateful if anybody would have a look at this. I'm
completely at loss, since I found out that even the version *with*
calls to abort() of the AJAX does indeed throw a exception in
FireFox.

I do not have the time to peruse your code again, but I can tell you two
things.

1) Depending on your use of your XHR object, abort() is not necessary.
For example, calling the open() method twice on a single XHR object
will reset the object, its connection (what was previously opened/sent),
and will disconnect any event handlers.

2) Firefox does not like the abort() method. Most notably in cases of
use in the onreadystatechange event.

NOTE: About the above, it is essential to use abort() in Firefox when
canceling an XHR request, just not in the above mentioned event.
 

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
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top