2011-08-24 59 views
2

我在系统中使用长轮询作为推送机制。 它在Chrome浏览器工作正常,但在IE8中行为很奇怪: 它加载5次正常(即,我能够刷新(F5)该页面5次,html被加载并且所有脚本都在运行正确)之后,IE8拒绝执行和网络连接(我检查了Fiddler2)并简单地显示“加载”图标无限。 现阶段唯一的治疗方法是关闭并打开浏览器本身。
我正在使用JQuery和PHP。IE8在5次长轮询请求后停止网络访问

这里是我的初始化代码:

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

长时间的搜索,我能够发现在另一个论坛回答后。为了其他可能遇到相同情况的开发者的利益,我在这里发布它。


嗨,

我有同样的问题。在HTML正文的卸载事件上中止AJAX请求解决了问题。

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插件自动执行此操作。

HTH, 马蒂亚斯Reischbacher

+0

更新:它已经改善,但远非完美。也许应该有某种插件收集所有的“ajax”请求并自动对其应用“中止”? –