2011-08-24 3 views
2

내 시스템에서 긴 폴링을 푸시 메커니즘으로 사용하고 있습니다. Chrome에서는 & 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

갱신 : 그것은하지만 지금까지 완벽한에서, 향상되었습니다. 어쩌면 모든 "아약스"요청을 수집하고 자동으로 "중단"을 적용하는 일종의 플러그인이 있어야할까요? –

관련 문제