已更新:jquery轮询解决方案
我试图让jquery智能轮询为我工作。如果进程在前2秒内准备就绪,那么它工作正常,但如果没有,它不会按照它的原样重试。我也想在一定数量后重试超时。
https://github.com/hmert/jquery-smart-poll
<script type="text/javascript" charset="utf-8">
$("#load_availables").toggle()
$.poll(2000,function(retry){
$.getScript('update_availables.js?job_id=<%= @bed.job_id %>&space_id=<%= @space.id %>', function(response, status){
if (status == 'success')
$("#load_availables").toggle() //works fine if ready
else
retry() //does not retry at all
})
})
</script>
谢谢,这可能会工作,但我只是注意到,重试,无论是在你的例子,甚至示例代码不起作用。它返回一个404,所以它没有做任何事情的成功,但它不会重试,因为它应该。 – holden 2011-04-14 10:28:03
您的代码中是否有重试功能?我不是100%确定你正在使用哪个外部插件库。 – 2011-04-14 10:43:57
使用jquery智能轮询https://github.com/jeremyw/jquery-smart-poll/blob/master/lib/jquery.smart-poll.js – holden 2011-04-14 10:46:40