IE8 stops network access after 5 long polling request
I am using Long Polling as a push mechanism in my system. It is working fine in Firefox & Chrome, but in IE8 the behaviour is quite strange: It loads OK for 5 times (i.e. I am able to refresh(F5) the page 5 times, the html is loaded and all scripts are running correctly) after which, IE8 refuses to perform and network connection (I've checked with Fiddler2) and simply shows the "loading" icon infinitely. The only cure at this stage, is to close and open the browser itself.
I am using JQuery and php.Here is my initialization code:
setTimeout( function() // called from $(function(){}), jquery page ready event
{
start_polling();
},1000);
function start_polling()
{
$.ajax(
{
url: "/push",
// must avoid cache because sometimes user is logged in and sometimes not
data:
{
"anticache":Math.random()
},
type: "post",
timeout: 30000, // half a minute before each restart long polling
success: func开发者_运维百科tion(data)
{
var dataObj = eval("("+data+")");
{
create_notif("withIcon",
{
title: dataObj.title,
text: dataObj.text,
icon: "/img/"+dataObj.type+".png"
},
{
click: function(e, instance)
{
instance.close();
}
});
}
start_polling();
},// end success of ajax load
error: function(x,t,m)
{
if(t==="timeout") {
//alert("got timeout");
start_polling();
} else {
//alert(t);
}
//start_polling();
}
}) // end ajax
} // start polling
After long searches I was able to find the answer in another forum. I publish it here for the benefit of other developers who might encounter the same situation.
Hi,
I had the same problem. Aborting the AJAX request on the unload event of the HTML body fixed the issue.
var activeRequest = null;
var atmosphere_result = function(src) {
activeRequest = null;
$("#content").html(src);//update div content
}
var atmosphere = function() {
activeRequest = $.ajax({
type:"GET",
cache:false,
url:'/atmosphere',
success: atmosphere_result
});
};
$(window).unload(function() {
if (activeRequest)
activeRequest.abort();
});
@Jeanfrancois: I think it would be a good idea to do this automatically in the new jQuery plugin.
HTH, Matthias Reischbacher
精彩评论