Time to start a counter on client-side.
Posted
by Felipe
on Stack Overflow
See other posts from Stack Overflow
or by Felipe
Published on 2010-06-07T12:58:19Z
Indexed on
2010/06/07
13:02 UTC
Read the original article
Hit count: 231
Hi everybody, I'm developing an web application using asp.net mvc, and i need to do a stopwatch (chronometer) (with 30 seconds preprogrammed to start in a certain moment) on client-side using the time of the server, by the way, the client's clock can't be as the server's clock. So, i'm using Jquery to call the server by JSon and get the time, but it's very stress because each one second I call the server to get time, something like this:
$(function() {
GetTimeByServer();
});
function GetTimeByServer() {
$.getJSon('/Home/Time', null, function(result) {
if (result.SecondsPending < 30) {
// call another function to start an chronometer
} else {
window.SetTimeout(GetTimeByServer, 1000); //call again each 1 second!
}
});
}
It works fine, but when I have more than 3 or 4 call like this, the browser slowly but works! I'd like to know, how improve more performace in client side, or if is there any way to do this... is there any way to client listen the server like a "socket" to know if the chronometer should start...
PS: Sorry for my english!
thanks Cheers
© Stack Overflow or respective owner