2011-08-24 56 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」請求並自動對其應用「中止」? –