javascript - jQuery AJAX: why is .error() method deprecated in favor of .fail()? -


if read link here .ajax() say:

jqxhr.fail(function( jqxhr, textstatus, errorthrown ) {}); alternative construct error callback option, .fail() method replaces deprecated .error() method. refer deferred.fail() implementation details.

why .error() method deprecated in favor of .fail()?

the 2 options equivalent.

however, promise-style interface (.fail() , .done()) allow separate code creating request code handling response.

you can write function sends ajax request , returns jqxhr object, , call function elsewhere , add handler.

when combined .pipe() function, promise-style interface can reduce nesting when making multiple ajax calls:

$.ajax(...)     .pipe(function() {          return $.ajax(...);     })     .pipe(function() {          return $.ajax(...);     })     .pipe(function() {          return $.ajax(...);     }); 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -