Reputation: 9230
I am trying to make the following recursive function work but keep receiving an error (following code):
var checkStatus = function(jobID) {
$.ajax({
type: 'post',
url: '/admin/process/check-encode-status.php',
data: {jobID: jobID},
success: function(data) {
if (data == 'processing') {
checkStatus(jobID).delay(2000);
} else {
$("#videoOutput").html(data);
}
}
});
};
The error I am receiving is: checkStatus(jobID) is undefined
Everything seems to be working as it should, Firebug is just throwing this warning. The function is repeating itself, posting the jobID and receiving "processing" from the PHP script.
I had a similar script that I was using that used setTimeout()
to be recursive but I could not figure out how to pass the jobID along with calling the function (errors).
Any ideas? Thanks!
Upvotes: 1
Views: 245
Reputation: 322502
Just remove the .delay()
and you'll get rid of the error. You should use setTimeout
instead.
var checkStatus = function (jobID) {
$.ajax({
type: 'post',
url: '/admin/process/check-encode-status.php',
data: {
jobID: jobID
},
success: function (data) {
if (data == 'processing') {
setTimeout(function() { // <-- send an anonymous function
checkStatus(jobID); // <-- that calls checkStatus
}, 2000);
} else {
$("#videoOutput").html(data);
}
}
});
};
This is because checkStatus()
doesn't return anything explicitly, so you're trying to call .delay()
on undefined
.
Upvotes: 3