如何根据返回重复AJAX请求



我有此代码:

.on('finish.countdown', function() {
                    var onEndAuction = function () {
                        $.ajax({
                            type: "POST",
                            url: "{{path('app_auction_end')}}",
                            data: {auctionId:{{ aReturn.oAuction.getId()}}},
                            success: function (data) {
                                console.log(data);
                                if (data == 0) {
                                    setTimeout(onEndAuction, i_timer);
                                } else {
                                    document.location.reload(true);
                                }
                            }
                        });
                    };
                });

我想要数据== 0需要在10秒后对app_auction_end进行另一个呼叫。你能帮我吗 ?提前thx,对不起我的英语

给操作一个命名函数:

var someFunction = function () {
    $.ajax({
        //...
    });
};

然后将其用于.on()调用:

.on('finish.countdown', someFunction)

和在success处理程序中,为该功能设置超时:

if (data == 0) {
    setTimeout(someFunction, i_timer);
}
.on('finish.countdown', function() {
  var onEndAuction = function () {
    $.ajax({
      type: "POST",
      url: "{{path('app_auction_end')}}",
      data: {auctionId:{{ aReturn.oAuction.getId()}}},
      success: function (data) {
        console.log(data);
        if (data == 0) {
          setTimeout(onEndAuction, i_timer);
        } else {
          document.location.reload(true);
        }
      }
    });
  };
  //do our initial call otherwise it will never get called.
  onEndAuction();
});

相关内容

  • 没有找到相关文章

最新更新