I am trying to do an AJAX refresh every 7 seconds on some data coming into an AJAX results div.
I need to control when it happens as I have lots of events like text editing and draggable stuff done through jQueryUI. I set up a function with a condition and an if statement to either set up an interval or clear it depending on the condition.
But my function seems to recognise a true state but not a false one. Any ideas or is their a better way to achieve what I want? Many thanks for your time!
var intervalStart = true;
function setupAjaxInterval(condition){
if (condition == true) {
var refreshContent = setInterval(function() {
var datastring = 'refreshpage=true&projid=' + proj_id + '&uid=' + uid;
ajaxUploadData(datastring);
alert('pagerefresh');
}, 7000);
}
else if (condition == false) {
clearInterval(refreshContent);
alert('nofresh');
}
}
setupAjaxInterval(intervalStart);
//works for true but not false.
You’re dealing with scope here.
You declare
var refreshCountwithin the if statement so it doesn’t exist in the else anymore.