0

I have multiple ajax calls that can fail. I would like to chain them all using something like below, but catch and react to any possible failure. If possible can you include a jsbin. Thanks.

first()
.then(function(){
    return second();
})
.then(function(){
    return third();
})
.fail(function(){
    // this should catch any failures above
    alert(failed)
})
Govind Samrow
  • 9,455
  • 13
  • 50
  • 85
David Choi
  • 4,941
  • 10
  • 27
  • 27
  • If I understand you correctly, catch() does what you're looking for. (https://api.jquery.com/deferred.catch/) – danh Sep 01 '17 at 04:20
  • Possible duplicate of [Chain multiple "then" in jQuery.when](https://stackoverflow.com/questions/17216438/chain-multiple-then-in-jquery-when) – Shiladitya Sep 01 '17 at 04:42

1 Answers1

0

first()
 .then(second)
 .then(function(data)
 {
   third
 })
 .catch(function(error_data){
     //code..
 });
Raga
  • 51
  • 5