I had this question regarding deferreds yesterday which was answered by @yury-tarabanko. The .done() call works perfectly. I'm now cleaning things up and adding a .fail() response. I've tried turning the server off and changing the URL to simulate a failed call but both don't seem to fire the .fail(). I'm just getting a failed "GET" message in the console.
function getStoreCounts() {
var campaignID = $("input[title='Campaign ID']").val();
var storeLists = $.ajax({
type: "GET",
dataType: "jsonp",
url: "https://storeLists/apiIndex?callback=?&campaign_code=" + campaignID.toString(),
}),
storeCount = storeLists.then(function(data) {
var counting = $.map(data,function(storeList) {
$.extend(storeList,{stores:''});
var getCount = $.ajax({
type: "GET",
dataType: "jsonp",
url: "https://storeLists/apiStoreCount?callback=?&list_id=" + storeList.id.toString(),
});
return getCount.then(function(count) {
storeList.stores = count;
});
});
return $.when.apply($,counting).then(function() {
return data;
});
});
storeCount.done(function(data) {
$.each(data,function(i,tierCount) {
$("input[title='Tier "+tierCount.name+" Kit Count']").val(tierCount.stores.toString());
});
}).fail(function(jqXHR, textStatus, errorThrown){
console.log("foo");
console.log(textStatus + ': ' + errorThrown);
});
}
Edit with Console shot of what I'm getting when the webservice is turned off. I'm not getting anything after the GET fails, no console logging of the error, not even the "foo".