IE8 stops network access after 5 long polling request

社会主义新天地 提交于 2019-12-11 00:44:42

问题


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: function(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

回答1:


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



来源:https://stackoverflow.com/questions/7175005/ie8-stops-network-access-after-5-long-polling-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!