IE8的长轮询问题

时间:2012-06-04 14:40:40

标签: jquery ajax long-polling

我正在构建一个使用长轮询技术的应用程序,我遇到了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不等待服务器响应,但是在第一次正确响应之后直接触发下一个请求或者死亡。 什么可能导致这种行为?

1 个答案:

答案 0 :(得分:0)

这似乎可以解决问题。

$.ajaxSetup ({
   cache: false
});
相关问题