Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serverSync with callback using synchronous XMLHttpRequest fails #65

Open
samgavinio opened this issue Apr 16, 2015 · 4 comments
Open

serverSync with callback using synchronous XMLHttpRequest fails #65

samgavinio opened this issue Apr 16, 2015 · 4 comments

Comments

@samgavinio
Copy link

The suggested serverSync implementation with synchronous XHR (taken from http://keith-wood.name/countdownRef.html)

$(selector).countdown({ 
    until:liftoffTime, serverSync: serverTime
}); 

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

would soon begin failing across all browsers due to the deprecation of synchronous XMLHttpRequests due to its negative effect on user experience. Please see: https://groups.google.com/a/chromium.org/forum/#!topic/chromium-extensions/WH1wOAxJQiM

At the moment there is no other way to use serverSync except for providing a callback that returns the server time using a synchronous XMLHttpRequest

@adis-me
Copy link

adis-me commented Dec 18, 2015

+1 This could be a showstopper soon.. Without async: false the serviceSync: serverTime is not working.

@tentonaxe
Copy link

You could of course simply defer the initialization of the plugin.

function startCountdown(serverTime) {
    $(selector).countdown({ 
        until:liftoffTime, serverSync: serverTime
    });
}

$.ajax({url: 'http://myserver.com/serverTime.php', 
    dataType: 'text', 
    success: function(text) { 
        startCountdown(new Date(text)); 
    }, 
    error: function(http, message, exc) { 
        startCountdown(new Date()); 
    }
}); 

@warrenkc
Copy link

@tentonaxe Have you had success with the serverSync? I have not gotten it to work. It seems like no matter what I do the countdowntimer is affected by a local system clock, and not using the server time.

@tentonaxe
Copy link

tentonaxe commented Mar 20, 2018

I never used serverSync, I just started the countdown after i retrieved the UTC datetime value from an ajax request. You can't stop the local system clock from impacting the countdown other than by calculating the difference between the two and then adjusting, but then if the user changes their clock after that point in time it'll be off again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants