I have two ajax calls i.e.
var ajax1 = $.ajax({ url: Url1 });
var ajax2 = $.ajax({ url: Url2 });
$.when(ajax1, ajax2).then(function (response1, response2) {
});
We want to conditionally handle the failure cases for these API deferred requests:
- If ajax1 is success and ajax2 is success: Call
WinAjax1_WinAjax2();
- If ajax1 is success and ajax2 fails: Call
WinAjax1_LoseAjax2();
- If ajax1 fails and ajax2 is success: Call
LoseAjax1_WinAjax2();
- If ajax1 fails and ajax2 fails: Call
LoseAjax1_LoseAjax2();
If I put logic in .fail
of respective ajax, I don't know what will the response of other ajax. If I put .fail
in .when
's failure, I am not able to identify which failure it is.
Could someone help how can I identify which ajax failed with multiple ajax requests once all the requests are completed?