複数の deferred が完了するのを待ってから、成功または失敗したコールバックを処理する必要があります。
function myFunc(){
alert("Success");
}
function myFailure(){
alert("Failure");
}
var jqxhr = $.ajax( "example.cfm" )
.done(function() { alert("Primo report"); })
.fail(function() { alert("Primo report non completato"); })
.always(function() { alert("Finito prima chiamata"); });
var jqxhr2 = $.ajax( "example2.cfm" )
.done(function() { alert("Secondo report"); })
.fail(function() { alert("Secondo report non completato"); })
.always(function() { alert("Finito seconda chiamata"); });
var jqxhr3 = $.ajax( "example3.cfm" )
.done(function() { alert("Terzo report"); })
.fail(function() { alert("Terzo report non completato"); })
.always(function() { alert("Finito terza chiamata"); });
$.when(jqxhr,jqxhr2,jqxhr3)
.then(myFunc, myFailure);
問題は、私の ajax リクエストの 1 つが失敗した場合、すぐにコールバックが発生することです。
すべての ajax リクエストが完了するまで待ってからコールバックすることは可能ですか?