Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
555 views
in Technique[技术] by (71.8m points)

c# - How countdown get Synchronise with jquery using "jquery.countdown.js" plugin?

Unable to get the correct Ans as i am getting correct result from the Jquery variable "shortly" but when i am Synchronise with function "serverSync" all will set to 0:0:0 i have checked both having a same date. ref. site http://keith-wood.name/countdown.html

here is my code

[WebMethod]
public static String GetTime()
{
    DateTime dt = new DateTime(); 
    dt = Convert.ToDateTime("April 9, 2010 22:38:10");  
    return dt.ToString("dddd, dd MMMM yyyy HH:mm:ss");
}

html file

<script type="text/javascript" src="Scripts/jquery-1.3.2.js"></script>

<script type="text/javascript" src="Scripts/jquery.countdown.js"></script>

<script type="text/javascript">
    $(function() {
        var shortly = new Date('April 9, 2010 22:38:10');
        var newTime = new Date('April 9, 2010 22:38:10');
        //for loop divid
        /// 
        $('#defaultCountdown').countdown({
            until: shortly, onExpiry: liftOff, onTick: watchCountdown, serverSync: serverTime
        });
        $('#div1').countdown({ until: newTime });
    });

    function serverTime() {
        var time = null;
        $.ajax({
            type: "POST",
            //Page Name (in which the method should be called) and method name
            url: "Default.aspx/GetTime",
            // If you want to pass parameter or data to server side function you can try line
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: "{}",
            async: false,
            //else If you don't want to pass any value to server side function leave the data to blank line below
            //data: "{}",  
            success: function(msg) {
                //Got the response from server and render to the client

                time = new Date(msg.d);
                alert(time);
            },
            error: function(msg) {
                time = new Date();
                alert('1');
            }
        });

        return time;

    }
    function watchCountdown() { }
    function liftOff() { }

</script>


See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You're setting the server time equal to the time you're counting down towards.

Since the new "serverSync" time and the "until" time are the same, the countdown will just be 0's across the board.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...