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,981
  • 13
  • 53
  • 90
David Choi
  • 6,131
  • 10
  • 28
  • 28
  • 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
  • 61
  • 5