Having problem with jQuery Countdown? Function serverSync: serverTime

前端 未结 3 728
名媛妹妹
名媛妹妹 2021-01-27 13:22

serverSync: serverTime Function return value from server but I have checked both server and client time both are same.When i called server to sync with server it will not displa

相关标签:
3条回答
  • 2021-01-27 13:29

    I realize this is almost a year old, but in case anyone has a similar problem, I thought of a solution that will avoid the complexity of AJAX. Since we're using the date on the server, we don't have to worry about the time on the client so we don't have to adjust for time zone or the clients clock being off. It should be as accurate as the network latency.

    <script type="text/javascript">
        jQuery(document).ready(
            function() {
                var eventTime = new Date('March 20, 2011 08:00:00');
                jQuery('#div_countdown').countdown({ until: eventTime,
                    serverSync: function() { return new Date('<%=DateTime.Now.ToString("ffffdd, dd MMMM yyyy HH:mm:ss")%>'); }
                });
            }
        );
    </script>
    
    0 讨论(0)
  • 2021-01-27 13:31

    Shouldn't you call serverTime() here -

    $('#defaultCountdown').countdown({
        until: shortly, onExpiry: liftOff, onTick: watchCountdown, serverSync: serverTime
    });
    

    Like this:

    $('#defaultCountdown').countdown({
        until: shortly, onExpiry: liftOff, onTick: watchCountdown, serverSync: serverTime()
    });
    
    0 讨论(0)
  • 2021-01-27 13:31
    async: true,
    

    That will fix the problem but it will not be synchronous. Maybe someone else can figure out why the async: false, will break this? I have no clue.

    0 讨论(0)
提交回复
热议问题