#767 enhancement
Mark Brown

Ajax reqests left open cause IE(6,7,8) to hang

Reported by Mark Brown | August 13th, 2009 @ 01:01 AM | in 2.0

In IE(6,7,8), if an http request is opened and the page navigates away or closes the window the browser can be become unresponsive.
I’ve been using a wrapper around Ajax requests like this to abort all open requests on unload which fixes the bug.

var requests = [];
Event.observe(window, 'unload', function() {
      if(requests) {
            for (i=0; i<requests.length; i++) {
                  requests[i].transport.onreadystatechange = Prototype.emptyFunction;
                  requests[i].transport.abort();
                  Ajax.activeRequestCount--;
            }
      }
});
AjaxRequest = function(a,b,c) {
      requests[requests.length] = new Ajax.Request(a,b,c);
}

To reproduce the bug:

-- index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>star rating control</title>
<link type="text/css" rel="stylesheet" href="css/PUStarRating.css" />
</head>
<body>
<a href="a.html" onclick="window.open('default.htm','Window1','menubar=no,width=430,height=360,toolbar=no'); return false;">a</a>
</body>
</html>

-- default.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>star rating control</title>
<script type="text/javascript" src="js/prototype.js"></script>
</head>
<body>
Requesting
<script type="text/javascript">
// When page is closed / redirected abort Ajax requests for IE
var requests = [];
Event.observe(window, 'unload', function() {

if(requests) {
    for (i=0; i&lt;requests.length; i++) {
        requests[i].transport.onreadystatechange = Prototype.emptyFunction;
        requests[i].transport.abort();
        Ajax.activeRequestCount--;
    }
}



}); AjaxRequest = function(a,b,c) {
requests[requests.length] = new Ajax.Request(a,b,c);



} for (i=0; i<5; i++) {
new AjaxRequest('slowPage.asp', {
    method: 'get',
    onSuccess: function(xhr) {
            // What did it GET ?
            alert('finished');
    },
    onFailure: function(xhr) {
            // Oops
            alert('Something went horribly wrong');
    }
});



} </script> </body> </html>
-- slowPage.asp
<%
For i = 1 To 10000000
i = i+1
Next
%>
Done

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins

Pages