I'm having issues with a javascript global variable (called TimeStamp) not being defined onload...at least I think that's the problem.
I start with this, defining TimeStamp.
$(document).ready(function(){
// AddTest();
var TimeStamp = null;
waitForMsg();
});
...waitForMsg then runs using TimeStamp and updated it on successful completion of the ajax call. At least that's the idea, but at the moment nothing runs because "TimeStamp is not defined"...even though I defined it earlier! (urgh).
If I re-define Timestamp within waitForMsg it just gets reset instead of using the updated value from the successfull ajax function.
function waitForMsg(){
$.ajax({
type: "POST",
url: "backend.php",
async: true,
cache: false,
timeout:50000, /* Timeout in ms */
data: "TimeStamp=" + TimeStamp,
success: function(data){
var json = eval('(' + data + ')');
$('#TextHistory :last-child').after('<p>' + json['msg'] + '</p>');
TimeStamp = json['timestamp'];
setTimeout(
'waitForMsg()', /* Request next message */
1000 /* ..after 1 seconds */
);
},
error: function(XMLHttpRequest, textStatus, errorThrown){
$('#TextHistory :last-child').after('<p>' + errorThrown + '</p>');
setTimeout(
'waitForMsg()', /* Try again after.. */
"15000"); /* milliseconds (15seconds) */
},
});
};
As always any help is greatly appreciated.
Dan.