Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用“倒计时”与jquery同步;jquery.countdown.js“;插件?_C#_Asp.net_Jquery - Fatal编程技术网

C# 如何使用“倒计时”与jquery同步;jquery.countdown.js“;插件?

C# 如何使用“倒计时”与jquery同步;jquery.countdown.js“;插件?,c#,asp.net,jquery,C#,Asp.net,Jquery,无法获得正确的Ans,因为我正在从Jquery变量“shorty”获得正确的结果,但当我与函数“serverSync”同步时,所有的Ans都将设置为0:0:0,我已检查两者是否具有相同的日期。 参考站点 这是我的密码 [WebMethod] public static String GetTime() { DateTime dt = new DateTime(); dt = Convert.ToDateTime("April 9, 2010 22:38:10");

无法获得正确的Ans,因为我正在从Jquery变量“shorty”获得正确的结果,但当我与函数“serverSync”同步时,所有的Ans都将设置为0:0:0,我已检查两者是否具有相同的日期。 参考站点

这是我的密码

[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文件


$(函数(){
var=新日期('2010年4月9日22:38:10');
var newTime=新日期('2010年4月9日22:38:10');
//for循环divid
/// 
$(“#默认倒计时”)。倒计时({
直到:很快,onExpiry:liftOff,onTick:watchCountdown,serverSync:serverTime
});
$('#div1')。倒计时({until:newTime});
});
函数serverTime(){
var-time=null;
$.ajax({
类型:“POST”,
//页面名称(应在其中调用方法)和方法名称
url:“Default.aspx/GetTime”,
//若要将参数或数据传递给服务器端函数,可以尝试使用第行
contentType:“应用程序/json;字符集=utf-8”,
数据类型:“json”,
数据:“{}”,
async:false,
//否则,如果您不想将任何值传递给服务器端函数,请将数据保留在下面的空行中
//数据:“{}”,
成功:功能(msg){
//从服务器获取响应并呈现给客户端
时间=新日期(msg.d);
警报(时间);
},
错误:函数(msg){
时间=新日期();
警报(“1”);
}
});
返回时间;
}
函数watchCountdown(){}
函数liftOff(){}


您将服务器时间设置为倒数计时的时间


由于新的“serverSync”时间和“until”时间相同,因此整个倒计时将为0。

如果您将倒计时插件从图片中删除,您的Webmethod是否返回值?重复问题:谢谢Doc hoffiday,但问题是我设置了“shorty”变量和“serverSync”返回相同的日期。很快,日期工作正常,但“serverSync”会在主板上显示0的帐户。我需要运行“serverSync”功能的倒计时。
<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>