jQuery deferred.fail() Method Last Updated : 11 Oct, 2021 Comments Improve Suggest changes Like Article Like Report The deferred.fail() method in jQuery is used to add handlers which are to be called when the Deferred object is rejected. This method accepts one or more than one arguments, which can be either a function or an array of functions. Callbacks are executed in the same order they were added. When the Deferred object is rejected, the failedCallbacks are called. Syntax: deferred.fail(failedCallbacks, failedCallbacks ) Parameters: failedCallbacks: This parameter specifies a function, or an array of functions, which are to be called when the Deferred is rejected.failedCallbacks: This parameter specifies the optional additional function, or an array of functions, which are to be called when the Deferred is rejected. Return Value: This method returns the deferred object. Example 1: html <!DOCTYPE HTML> <html> <head> <script src= "https://code.jquery.com/jquery-3.5.0.js"> </script> </head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksForGeeks </h1> <p> JQuery | deferred.fail() method </p> <button onclick="Geeks();"> click here </button> <script> function Geeks() { $.get("testingGFG.php") .done(function () { alert("$.get successfully completed!"); }) .fail(function () { alert("$.get failed!"); }); } </script> </body> </html> Output: Before clicking on button: After clicking on button: Example 2: html <!DOCTYPE HTML> <html> <head> <script src= "https://code.jquery.com/jquery-3.5.0.js"> </script> </head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksForGeeks </h1> <p> JQuery | deferred.fail() method </p> <button onclick="Geeks();"> click here </button> <p id="GFG_DOWN"></p> <script> var el_down = document.getElementById("GFG_DOWN"); function Geeks() { $.get("testingGFG.php") .done(function () { el_down.innerHTML = "$.get successfully completed"; }) .fail(function () { el_down.innerHTML = "$.get failed!"; }); } </script> </body> </html> Output: Comment More infoAdvertise with us Next Article jQuery deferred.fail() Method P PranchalKatiyar Follow Improve Article Tags : JavaScript Web Technologies JQuery jQuery-Methods Similar Reads JQuery .Deferred() method This JQuery.Deferred() method in JQuery is a function which returns the utility object with methods which can register multiple callbacks to queues. It calls the callback queues, and relay the success or failure state of any synchronous or asynchronous function.Syntax:jQuery.Deferred([beforeStart])P 2 min read jQuery deferred.done() Method This deferred.done() method in jQuery is used to add handlers which are to be called when the deferred object is resolved.Syntax:Â deferred.done(Callbacks [, Callbacks])Parameters:Callbacks: This parameter specifies a function, or array of functions, which are called when the Deferred is resolved.Cal 1 min read JQuery deferred.then() method This deferred.then() method in JQuery is used to add handlers which are to be called when the Deferred object is resolved, rejected, or in progress. Syntax: deferred.then(doneCallbacks[, failCallbacks][, progressCallbacks])Parameters: doneCallbacks: This is a function, or an array of functions, whic 3 min read JQuery deferred.pipe() Method The deferred.pipe() method in jQuery is used to add utility method to filter, chain Deferreds.Syntax:deferred.pipe([doneFilter][, failFilter][, progressFilter])Parameters: This method accepts three parameter as mentioned above and described below:doneFilter: It is an optional function which is calle 2 min read jQuery deferred.catch() Method The deferred.catch() method in jQuery is used to add handlers which are to be called when the deferred object is rejected. Syntax:deferred.catch(failedFilter)Parameters:failedFilter: This parameter specifies a function which is to be called when the deferred object is rejected.Return Value: This met 1 min read Like