通过执行ajax方式返回服务器时间
*/
$(document).ready(function (){
var url=/ajax/comm.shtml?action=getTime;
jQuery.ajax(url,{
data: ,
dataType: json,
cache: false,
success: function(req){
callbackTime(req);
},
error: function(msg){
alert(ERROR:请刷新页面!);
}
});
$(#but1).click(function(){jqueryTest();});
});
var srv_nowtime;
function callbackTime(req){
var timeArr = req.split(&);
srv_nowtime = new Date(timeArr[0]).getTime();
showTime();
window.setInterval(showTime, 1000);
}
function showTime(){
srv_nowtime += 1000;
var nowtime = new Date(srv_nowtime);
var ymd = nowtime.getFullYear() + + (nowtime.getMonth()+1) ++ (nowtime.getDate()10?0+nowtime.getDate():nowtime.getDate());
//alert(ymd);
}
执行之后就会显示服务器时间
取消
评论