Search code examples
phpjquerytimeclockcountdown

Jquery Countdown Server sync issue


I'm trying to create a countdown for an event. I'm using Jquery Countdown

I have this code:

$(function () {
    var fecha = new Date("July 30, 2011 00:00:00");
    $('#defaultCountdown').countdown({
        until: fecha,
        format: 'DHMS',
        expiryUrl: "http://www.google.com",
        serverSync: serverTime,
        timezone: -4
    });


});


function serverTime() {
    var time = null;
    $.ajax({
        url: 'serverTime.php',
        async: false,
        dataType: 'text',
        success: function (text) {
            time = new Date(text);
        },
        error: function (http, message, exc) {
            time = new Date();
        }
    });
    return time;
}

The script is working fine, but when I try to change the clock date, the countdown changes. Any idea why?


Solution

  • I imagine you created the serverTime.php file on your server? http://keith-wood.name/countdown.html Tab Timezones has the PHP code you'll need to add to serverTime.php for your script to use that. Also may want to fully qualify that to something like url: 'http:yourdomain.com/serverTime.php' But using that it should use your server time not your local PC time. If your server is on your local PC, then well... it would change.