Reputation: 153
I use the code below to auto reload a small frame at the top of my website every 60 seconds, but every time it reloads, it freezes (cannot click on anything) for about 10-20 seconds, sometimes even constantly until the page is manually refreshed. Is there a way to stop this happening?
$(function() {
$('#stats').load('statsto.php');
var visibleInterval = 60000;
var invisibleInterval = 60000;
$(function() {
setTimer();
$(document).bind('visibilitychange'), function() {
clearTimeout(timer);
setTimer();
};
});
function displayStats() {
$('#stats').load('statsto.php');
$.ajaxSetup({ cache: false });
}
function setTimer() {
timer = setInterval(displayStats, (document.hidden) ? invisibleInterval : visibleInterval);
}
});
Upvotes: 0
Views: 653
Reputation: 2139
More than likely your ajax request has async: false
. Try changing that to true to allow the ajax to be performed while other stuff is done.
Upvotes: 1