有jQuery倒计时的问题? functionserverSync:serverTime

serverSync:serverTime函数从服务器返回值,但我检查了服务器和客户端时间都相同。当我调用服务器与服务器同步时,它不会显示倒计时。 帮我 ?

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

我意识到这已经快一年了,但是如果有人遇到类似的问题,我想到了一个可以避免AJAX复杂性的解决方案。 由于我们在服务器上使用日期,因此我们不必担心客户端上的时间,因此我们无需调整时区或客户端时钟关闭。 它应该与网络延迟一样准确。

  

你不应该在这里调用serverTime() –

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

像这样:

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

这将解决问题,但不会同步。 也许其他人可以弄清楚为什么async: false ,会打破这个? 我没有线索。