これをjQuery 1.7でコーディングしました:
$.when($.ajax({
type: "GET",
url: internalOrderServiceURL,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: $.proxy(this.retrieveInternalOrderSuccess, this),
error: $.proxy(this.retrieveInternalOrderError, this)
}), $.ajax({
type: "GET",
url: rejectionReasonServiceURL,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: $.proxy(this.retrieveRejectionReasonSuccess, this),
error: $.proxy(this.retrieveRejectionReasonError, this)
})
).done(
$.ajax({
type: "GET",
url: salesOrderInfoServiceURL,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: $.proxy(this.retrieveServiceItemSuccess, this),
error: $.proxy(this.retrieveServiceItemError, this)
})
);
ただし、コールバック retrieveServiceItemSuccess は、retrieveInternalOrderSuccess および retrieveRejectionReasonSuccess の前に実行されます。何が問題なのか誰か教えてくれませんか?
コードを次のように変更しました。
$.when($.ajax({
type : "GET",
url : internalOrderServiceURL,
contentType : "application/json; charset=utf-8",
dataType : "json",
success : $.proxy(this.retrieveInternalOrderSuccess, this),
error : $.proxy(this.retrieveInternalOrderError, this)
}), $.ajax({
type : "GET",
url : rejectionReasonServiceURL,
contentType : "application/json; charset=utf-8",
dataType : "json",
success : $.proxy(this.retrieveRejectionReasonSuccess, this),
error : $.proxy(this.retrieveRejectionReasonError, this)
})).done(function() {
$.ajax({
type : "GET",
url : salesOrderInfoServiceURL,
contentType : "application/json; charset=utf-8",
dataType : "json",
success : $.proxy(this.retrieveServiceItemSuccess, this),
error : $.proxy(this.retrieveServiceItemError, this)
})
});
しかし今回は、最初のコールバック retrieveInternalOrderSuccess が実行され、次に 2 番目のコールバックが実行されます (retrieveRejectionReasonSuccess)。これら 2 つのコールバックの実行順序はランダムです。ただし、3 番目のコールバックは実行されません。誰が何が悪いのかアドバイスできますか?
私はこれを追加しようとしました:
var self = this;
$.when($.ajax({
type : "GET",
url : internalOrderServiceURL,
contentType : "application/json; charset=utf-8",
dataType : "json",
success : $.proxy(this.retrieveInternalOrderSuccess, this),
error : $.proxy(this.retrieveInternalOrderError, this)
}), $.ajax({
type : "GET",
url : rejectionReasonServiceURL,
contentType : "application/json; charset=utf-8",
dataType : "json",
success : $.proxy(this.retrieveRejectionReasonSuccess, this),
error : $.proxy(this.retrieveRejectionReasonError, this)
})).done(function() {
$.ajax({
type : "GET",
url : salesOrderInfoServiceURL,
contentType : "application/json; charset=utf-8",
dataType : "json",
success : function(oResult) {
self.retrieveServiceItemSuccess(oResult);
},
error : function(oResult) {
self.retrieveServiceItemError(oResult);
},
})
});
今回はコールバックが正しい順序で呼び出されます。誰でもこれを明確にできますか?