Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery 1.9 - Internet Explorer 9 freezes after first $ajax request

For a dynamic page, I use Ajax Long Polling and even with jQuery 1.9, Internet Explorer hangs after the first request.

The script code is based on the article Simple Long Polling Example with JavaScript and jQuery

 <script type="text/javascript" charset="utf-8"> 
   $(document).ready(function(){ 
     (function poll(){
       $.ajax({ url: "ajaxstats.json", success: function(data){
         $("button.requests" ).empty().append(data.requests);
   }, dataType: "json", complete: poll, timeout: 30000 });
     })();
   });
 </script>

The console shows no errors.

The IE network monitor immediately shows many requests to the ajaxstats.json resource with a response time of < 1 ms and a 304 (not modified) response code. The response body is correct (JSON code).

The server code always delays the answer by 1000 milliseconds. And in Firefox, Firebug XHR log shows that every request takes around 1000 milliseconds, as expected.

The HTTP response code is different between Firefox and Internet Explorer:

  • in Firefox: response code is 200 ok
  • in Internet Explorer 9, the response code is 304 (not modified)

Is there a way to work around this IE problem?

like image 293
mjn Avatar asked Jan 31 '13 14:01

mjn


1 Answers

Try setting cache param to false, if set to false, it will force requested pages not to be cached by the browser.

 <script type="text/javascript" charset="utf-8"> 
   $(document).ready(function(){ 
     (function poll(){
       $.ajax({ url: "ajaxstats.json", success: function(data){
         $("button.requests" ).empty().append(data.requests);
   }, dataType: "json", complete: poll, timeout: 30000, cache: false });
     })();
   });
 </script>
like image 135
Corneliu Avatar answered Oct 25 '22 16:10

Corneliu