尝试
setTimeout(function () {
var timestamp_last_check = 0; //declare here to make it available to data:
$.ajax({
'method': 'POST',
'url': '/ajax/request_news',
'beforeSend': function () {
alert('Before send')
date = new Date()
timestamp_last_check = Math.floor(date.getTime() / 1000); //set Value here
},
问题强>
var timestamp_last_check仅限于beforeSend:,因此无法在该区域外访问。
'beforeSend': function () {
alert('Before send')
date = new Date()
var timestamp_last_check = Math.floor(date.getTime() / 1000)
},
在OP的评论
之后更新
function doPoll() {
alert('GO POLL');
setTimeout(function () {
var date = new Date();
var timestamp_last_check = Math.floor(date.getTime() / 1000);//set value here
$.ajax({
'method': 'POST',
'url': '/ajax/request_news',
'data': {
'last_check': timestamp_last_check
},
'success': function (ret) {
ret = $.parseJSON(ret)
},
'complete': function () {
doPoll()
}
})
}, 5000)
};