Problem with window.setinterval in IE11 (due to browser caching JSON response)

I wrote a JavaScript method to load content into my page with an interval of one second. It works fine in Chrome and Firefox, but not in Internet Explorer. Automatic reboot after 1000 ms does not work.

How to fix it?

function testing() {
    $.getJSON('test.php', function(data) {
        var lastresult = data.lastresult;
        $('#test').html(lastresult);
    }); 
}

// Execute testing() after every 1 second
window.setInterval(function(){testing()}, 1000);

EDIT (I found a solution): IE cached the result test.php, so it doesn't seem to work for me. Adding this to the script worked:

jQuery.ajaxSetup({ cache: false });

Also, I tried the code below and they worked for me.

Example 1 (worked):

function testing() {
    $.getJSON('test.php', function(data) {
        var lastresult = data.lastresult;
        $('#test').html(lastresult);        
    }); 
}

testing(); // Worked!

Example 2 (worked):

function testing() {
    alert('test');
}

window.setInterval(function(){testing()}, 1000); // worked
+3
source share

All Articles