Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
66
rated 0 times [  68] [ 2]  / answers: 1 / hits: 5082  / 11 Years ago, fri, february 14, 2014, 12:00:00

I'm thinking on a clock that will refresh every full minute if system clock on users computer will look like this eg. 11:08:00, it'll refresh and 11:09:00 etc.



I've tryed to setInterval():



setInterval(function(){
$.ajax({
url: ../time.php,
context: document.body,
success: function(result){
$('.time').html(result);
}
})
}, 60000);


But it's reloading every minute after page load.



Is there any solution?


More From » jquery

 Answers
7

Try this code:



var interval    =   0;
function start(){
setTimeout( function(){
ajax_function();
interval = 60;
setInterval( function(){
ajax_function();
}, interval * 1000);
}, interval * 1000);
}

function ajax_function(){
$.ajax({
url: ../time.php,
context: document.body,
success: function(result){
$('.time').html(result);
}
});
}

$( window ).load(function(){
var time = new Date();
interval = 60 - time.getSeconds();
if(interval==60)
interval = 0;
start();
});

[#47725] Thursday, February 13, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jocelynkarsynr

Total Points: 472
Total Questions: 98
Total Answers: 96

Location: Macau
Member since Mon, Nov 16, 2020
4 Years ago
jocelynkarsynr questions
Tue, Feb 8, 22, 00:00, 2 Years ago
Sat, Jul 11, 20, 00:00, 4 Years ago
Sun, May 10, 20, 00:00, 4 Years ago
Sat, Jan 18, 20, 00:00, 4 Years ago
;