jQuery 递归函数错误
我正在尝试使以下递归函数工作,但不断收到错误(以下代码):
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);
}
}
});
};
我收到的错误是: checkStatus(jobID) is undefined
一切似乎都按预期工作,Firebug只是抛出这个警告。该函数不断重复自身,发布 jobID 并从 PHP 脚本接收“处理”。
我有一个类似的脚本,我正在使用它使用 setTimeout() 进行递归,但我无法弄清楚如何传递 jobID 以及调用函数(错误)。
有什么想法吗?谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需删除
.delay()
即可消除错误。您应该使用setTimeout
来代替。这是因为
checkStatus()
不会显式返回任何内容,因此您尝试在undefined
上调用.delay()
。Just remove the
.delay()
and you'll get rid of the error. You should usesetTimeout
instead.This is because
checkStatus()
doesn't return anything explicitly, so you're trying to call.delay()
onundefined
.