2012-06-04 64 views
0

即時通訊建立一個應用程序,使用長輪詢技術和即時通訊運行IE8的一些麻煩。長時間輪詢問題與IE8

所以這裏是簡化的代碼,我使用:

PHP:

$time = time(); 
    while((time() - $time) < 10) { 
     $data = rand(0,10);  
     // if we have new data return it 
     if($data == 3 || $data == 6) { 
      echo json_encode($data); 
      break; 
     } 
      sleep(1); 
     } 

JS:

var lpOnComplete = function(response) { 
     alert(response); 
     // do more processing 
     lpStart(); 
    }; 

    var lpStart = function() { 
     $.post('http://example.com/test', {}, lpOnComplete, 'json'); 
    }; 

    $(document).ready(lpStart); 

的問題似乎是,IE8不會等待直到服務器響應但會在第一個正確響應後直接觸發下一個請求或死亡。 什麼可能導致此行爲?

回答

0

這似乎是個竅門。

$.ajaxSetup ({ 
    cache: false 
});