2016-07-15 21 views
0

昨天我有this question regarding deferreds這是由@ yury-tarabanko回答的。 .done()調用完美。我現在正在清理並添加一個.fail()響應。我嘗試關閉服務器並更改URL以模擬失敗的調用,但兩者似乎都不會觸發.fail()。我只是在控制檯中收到失敗的「GET」消息。

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); 
    }); 
} 

編輯與控制檯拍攝我得到什麼時,web服務被關閉。在GET失敗後,我沒有得到任何東西,沒有控制檯記錄錯誤,甚至沒有「foo」。

enter image description here

回答

0

似乎運作得很好。你得到了什麼結果,你期望得到什麼結果?

enter image description here