I am trying to create a count-down timer using mysql, php and javascript. I am trying to make the ending-time a constant and stored in mysql server, then it is queried every second from javascript via php. Then, I am getting the current time in javascript, every second using new Date() function. subtracting the current time from ending-time gives me the time left.
However, my problem is that when the website is viewed in different devices, the current time queried using javascript is varied by seconds and sometimes even minutes... Please help me solve this problem.
Here's what I have tried.
setInterval(function()
{
$.post('QueryTime.php', 'get=true', function(data,status)
{
if(status)
var endingtime = data;
else
alert("Server Error! Please refresh the page.");
});
endingtime = parseInt(endingtime);
var now = new Date();
now = now.getTime();
var timeleft = (date - now)/1000;
},1000);