I'm running a function that checks a remote script every second and updates a progress bar. I'm new with setInterval
and am having an issue with getting it to stop looping after it's done.
I've added var interval
post function, and clearInterval(interval);
in several different places - basically like covering my eyes and pinning the tail on the donkey - and have had no success. Where would I set clearInterval
to stop the loop once data
has reached 100?
function getProgress(hash) {
setInterval(function() {
$.ajax({
type: 'GET',
url: 'http://domain.com/script.php?hash=' + hash,
cache: false,
dataType: 'json',
success: function(data) {
if (data < 100) {
getProgress();
} else {
$('#progress-bar').hide();
}
},
});
}, 1000);
}