Search code examples
jqueryajaxlong-polling

Long polling issue with IE8


Im building an app that uses long polling technique and im running into some trouble with IE8.

so here is the simplified code that i use:

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);

The problems seems to be that IE8 is not waiting til the server responds but fires the next request straight after or dies after first proper response. What may cause this behavior?


Solution

  • This seemed to do the trick.

    $.ajaxSetup ({
       cache: false
    });