-1

我有这个代码:

.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);
                                }
                            }
                        });
                    };
                });

我想如果 data == 0 需要app_auction_end在 10 秒后再次调用。你能帮我吗 ?提前谢谢,对不起我的英语

4

2 回答 2

1

给操作一个命名函数:

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

然后您将用于您的.on()通话:

.on('finish.countdown', someFunction)

success处理程序中,为该函数设置超时:

if (data == 0) {
    setTimeout(someFunction, i_timer);
}
于 2016-11-21T20:29:53.590 回答
0
.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();
});
于 2016-11-21T20:49:20.243 回答