有问题jQuery的倒计时?功能serverSync:serverTime [英] Having problem with jQuery Countdown? Function serverSync: serverTime

查看:257
本文介绍了有问题jQuery的倒计时?功能serverSync:serverTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

serverSync:从服务器serverTime函数返回值,但我已经检查服务器和客户端的时间都是same.When我叫服务器服务器时,它不会显示倒计时同步。帮帮我吗?

  $(函数(){
        VAR不久=新的日期();
        VAR NEWTIME =新的日期(2010年4月9日20点38分10秒');
        // for循环DIVID
        ///
        $('#defaultCountdown')。倒计时({
            直到:不久,onExpiry:升空,onTick:watchCountdown,serverSync:serverTime
        });
        $('#DIV1)倒计时({直至:NEWTIME});
    });
    功能serverTime(){
        VAR时间= NULL;
        $阿贾克斯({
            键入:POST,
            //页面名称(中,该方法应被调用)和方法名
            网址:Default.aspx的/ GETTIME
            //如果你想参数或数据传递给服务器端的功能,你可以尝试线
            的contentType:应用/ JSON的;字符集= UTF-8,
            数据类型:JSON
            数据:{},
            异步:假的,
            //否则如果你不希望传递给服务器端功能的任何值保持数据低于空白行
            //数据:{},
            成功:函数(MSG){
                //得到服务器的响应并呈现给客户端                时间=新的日期(msg.d);
                警报(时间);
            },
            错误:函数(MSG){
                时间=新的Date();
                警报('1');
            }
        });
        不久=时间;
        返回时间;    }
 [的WebMethod]
公共静态字符串GETTIME()
{
    DateTime的DT =新的DateTime();
    DT = Convert.ToDateTime(2010年4月9日22点38分10秒);
    返回dt.ToString(DDDD,DD MMMM YYYY HH:MM:SS);
}


解决方案

我意识到这是近一年的老,但如果任何人有类似的问题,我想到了一个解决方案,将避免AJAX的复杂性。由于我们使用了服务器上的日期,我们不必担心客户端上的时间,所以我们没有调整时区或客户端的时钟被关闭。它应该是作为网络延迟准确。

 <脚本类型=文/ JavaScript的>
    jQuery的(文件)。就绪(
        功能(){
            VAR EVENTTIME =新的日期('二零一一年三月二十日08:00:00');
            jQuery的('#div_countdown)倒计时({到:EVENTTIME,
                serverSync:函数(){返回新日期('<%= DateTime.Now.ToString(DDDD,DD MMMM YYYY HH:MM:SS)%>'); }
            });
        }
    );
< / SCRIPT>

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 display countdown. help me ?

    $(function() {
        var shortly = new Date();
        var newTime = new Date('April 9, 2010 20: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');
            }
        });
        shortly = time;
        return time;

    }
 [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");
}

解决方案

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("dddd, dd MMMM yyyy HH:mm:ss")%>'); }
            });
        }
    );
</script>

这篇关于有问题jQuery的倒计时?功能serverSync:serverTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆