1

成功コールバックを使用すると、このソリューションは正常に機能しますが、.done() を使用すると、これが失敗します。元の .done() .fail() および complete() 登録済みコールバックを使用して、キューに入れられた ajax リクエストを再試行するにはどうすればよいですか?

var requestQueue = [];
        $.ajaxSetup({ 
            cache: false,
            beforeSend: function (jqXHR, options) {                                 
                if(true){ //any condition 'true' just demonstrate
                    requestQueue.push({request:jqXHR,options:options});
                    //simulate process this queue later for resend the request
                    window.setTimeout(function(){
                        //this will work with success callbak option, 
                        //but with .done() the console.log("Well Done!");
                        // will fail                            
                        $.ajax($.extend(requestQueue.pop().options, {global:false, beforeSend:null}));
                    }, 3000)
                    return false;
                }
            }           
        });
        $.ajax({
            url:"TesteChanged.html",
            error: function(){
                console.log("Oh nooooo!");
            }
        }).done(function(){
            console.log("Well Done!");
        });

後で再送信するために ajax 呼び出し (条件に基づく) をキューに入れたいのですが、再送信するときは、元のコールバック .done()/.fail() を呼び出す必要があります。'success' コールバック オプションを使用すると、このコードは正常に機能します。

4

1 に答える 1