开发者

jquery polling solution

UPDATED:

I'm trying to get jquery smart poll to work for me. It works fine if the process is ready in the first 2 seconds but if not, it does not retry as it's supposed to. I'd also like to make the retries time out after a certain number.

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>


var retryCount = 0;

$.poll(10000, function(retry){
     retryCount++;
     $.get('something', function(response, status){
       if (status == 'success')
         // Do something
       else
       {
         if(retryCount < 11) retry();
         else return;
       }
     })
   })

I haven't had the chance to test this - but, in theory this should do the job.

By the way, as a side note - for the thing you're doing if you'd like to speed up efficiency of your JavaScript, use a comet server and use slow polling. Take a look at http://www.ape-project.org/


take a look at the jquery plugin Smartupdater

http://www.eslinstructor.net/smartupdater3/

It has all features you need.


Better late than never! According the the jQuery docs the get() ajax function fails silently. You will have to handle the .ajaxError() event. http://api.jquery.com/ajaxError/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜