本文介绍了jQuery的轮询与智能民意调查插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$。poll(10000,function(retry){
$ .get('willfail',function(response,status){
if(status =='success')) {
//做某事
alert(YES);
} else {
alert(NO);
// retry();

})
})

如果我设置了get请求到'/'它会给我警告YES消息,但事实上,即使ELSE,警报无信息永远不会被解雇。



我正在使用jquery投票插件:





有什么想法?

解决方案

这可能是一个不好的例子。回传给只会在请求成功时触发。试试这个:

$ $ $ $ $ $ $ $ $ $ poll $(10000,function(retry){
$ .ajax({
url:'willfail',
成功:function(){
//做某事
alert(YES);
},
error:function( ){
alert(NO);
retry();
}
});
});

有关更多信息,请查看。

I'm trying for the life of me to get this plugin to work but I'm not understanding the status function so retry is not firing.

$.poll(10000, function(retry){
  $.get('willfail', function(response, status){
    if (status == 'success') {
      // Do something
      alert("YES");
    } else {
      alert("NO");
      //retry();
    }
  })
})

If I set the get request to '/' it will give me the alert YES message, but as it is, the alert No message never gets fired despite the ELSE.

I'm using a jquery polling plugin:

https://github.com/jeremyw/jquery-smart-poll

Any ideas?

解决方案

That is probably a bad example. The callback passed to $.get will only be fired if the request succeeded. Try this:

$.poll(10000, function(retry){
  $.ajax({
      url:'willfail',
      success: function(){
          // Do something
          alert("YES");
      },
      error: function() {
          alert("NO");
          retry();
      }
  });
});

For more information, have a look at $.ajax.

这篇关于jQuery的轮询与智能民意调查插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 16:18