Answer the question
In order to leave comments, you need to log in
How to do a background page refresh?
How can I make it so that when the page is open, the reload.php page is updated in the background every 2 seconds, and when it is updated, .loader is shown?
Answer the question
In order to leave comments, you need to log in
function reload( delta ) {
var delta = delta || 0;
setTimeout(function(){
$('.loader').show();
var start = newDate().getTime();
$.ajax(url : "reload.php", success : function(data){
....data manipulation
$('.loader').hide();
var end = newDate().getTime();
reload( end - start );
});
},2000 - delta);
});
reload();
var uTimeout = false, uRequest = false, uFunction = function(){
if (uRequest !== false) {
uRequest.abort();
}
if (uTimeout !== false) {
clearTimeout(uTimeout);
}
uTimeout = setTimeout(function(){
uRequest = $.get('reload.php', {}, function(q){
/* действия с DOM */
uRequest = false;
uTimeout = false;
uFunction();
});
}, 2000);
};
uFunction();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question