我正在使用带有以下代码的jquery倒计时插件。
$('#countbox').countdown({
layout:'<b>{d<}{dnn}:{d>}'+
'{hnn}: {mnn} : {snn} </b>',
timeSeparator: ':',
onExpiry: sold,
onTick: highlight,
serverSync: serverTime
});
function serverTime(pid) {
var time = null;
$.ajax({
url: 'ajax_countdown',
async: false,
data: ({pid:pid}),
dataType: 'text',
success: function(text) {
time = new Date(text);
},
error: function(http, message, exc) {
time = new Date();
}});
alert(time);
return time;
}
问题1:使用此我正在调用函数serverTime
,我想将值pid
传递给方法。我如何实现这一目标?
问题2与javascript Date
函数
$d4 ="2011,01-1,11,23,31,32";
alert(new Date(<?php echo $d4; ?>));
当我运行上面的代码时,我得到以下结果
2011年1月11日星期二23:31:32 GMT + 0530 (印度标准时间)
但是,ajax调用(如上所述)也返回相同的结果,但在这种情况下,当我发出警报时,我收到以下响应
无效日期
警报(时间);
为什么在第二种情况下这有所不同,如何更改我的代码以接收我想要的行为?
答案 0 :(得分:1)
“警报”在ajax答案返回之前触发......将其包含在成功函数中......或者从成功中调用函数..
function serverTime(pid) {
var time = null;
$.ajax({
url: 'ajax_countdown',
async: false,
data: ({pid:pid}),
dataType: 'text',
success: function(text) {
time = new Date(text);
alert(time);
return time;
},
error: function(http, message, exc) {
time = new Date();
}});
}
答案 1 :(得分:0)
我为此得到了答案 问题1:使用这个我正在调用函数serverTime。在这里我想将值pid传递给method.how来做到这一点?
代码片段尚未经过测试,但我希望它可以正常使用。
$('#countbox').countdown({
layout:'<b>{d<}{dnn}:{d>}'+
'{hnn}: {mnn} : {snn} </b>',
timeSeparator: ':',
onExpiry: sold,
onTick: highlight,
serverSync: function() { serverTime(pid); }
});
function serverTime(pid) {
alert(pid);
}