IE8在5个长轮询请求后停止网络访问 [英] IE8 stops network access after 5 long polling request

查看:552
本文介绍了IE8在5个长轮询请求后停止网络访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在系统中使用Long Polling作为推送机制。
它在Firefox& Chrome,但在IE8中的行为很奇怪:
它加载OK 5次(即我能够刷新(F5)页面5次,加载html并且所有脚本都正确运行)之后, IE8拒绝执行和网络连接(我已经与Fiddler2核对过),只是无限地显示加载图标。
在这个阶段唯一的解决方法是关闭并打开浏览器本身。

我使用的是JQuery和php。

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


推荐答案

经过长时间的搜索,我能够在另一个论坛找到答案。我在这里发布它是为了其他可能遇到相同情况的开发人员的利益。

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.

我遇到了同样的问题。在HTML正文的卸载事件中中止AJAX请求修复了问题。

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:我认为在新的jQuery插件中自动执行此操作会是一个好主意。

@Jeanfrancois: I think it would be a good idea to do this automatically in the new jQuery plugin.

HTH,
Matthias Reischbacher

HTH, Matthias Reischbacher

这篇关于IE8在5个长轮询请求后停止网络访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆