MattCode
MattCode

Reputation: 1

Jquery reload DIV every x seconds not working in FireFox or IE

I am new to Jquery I have some code that reloads a DIV every x seconds which works fine in Safari on iPhones and iPads but doesn't seem to work in FireFox or IE, I think it's a cache problem. Can anyone point out what I am doing wrong or how to avoid cache in FF and IE.

<script>
$(function() 
{
startRefresh();
});
function startRefresh() 
{ 
setTimeout(startRefresh,1000);
$.get('index.htm', function(data) 
{
    $('#container').html(data);  
 });
}
</script>

Upvotes: 0

Views: 99

Answers (1)

RBoschini
RBoschini

Reputation: 506

This problem maybe is cache, try this.

function startRefresh() 
{ 
   $.ajaxSetup({ cache: false }); //Try disable cache!!!
   var rnd = Math.random();
   $.get('index.htm?v='+rnd, function(data) 
   {
      $('#container').html(data);  
   });
}
var interval;
$(document).ready(function(){
  interval = setInterval(startRefresh,1000);
});

Generate a random number and send with parameter, brownser force get new version of page.

SetTimeout runs one time and setInterval run aways and you be clear with clearInterval(myInterval)

see more about ajaxSetup.

try and let me know.

Upvotes: 2

Related Questions