Try
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
},
Problem
var timestamp_last_check
is local to the beforeSend:
only so it is not accessible outside the block.
'beforeSend': function () {
alert('Before send')
date = new Date()
var timestamp_last_check = Math.floor(date.getTime() / 1000)
},
Read What is the scope of variables in JavaScript?
Updated After OP's comment
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)
};