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 called when the Deferred is resolved.
- failFilter: This is an optional function which is called when the Deferred is rejected.
- progressFilter: This is an optional function which is called when progress notifications are being sent to the Deferred object.
Return Value: This method returns the deferred object.
Example 1: In this example, the pipe method is called with resolve method.
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;" > w3wiki </ h1 > < p > JQuery | deferred.pipe() method </ p > < button onclick = "Beginner();" > click here </ button > < p id = "GFG" ></ p > < script > function Beginner() { var def = $.Deferred(), filter = def.pipe(function (val) { return "pipe() is called with " + val; }); def.resolve('resolve method'); filter.done(function (val) { $('#GFG').append(val); }); } </ script > </ body > </ html > |
Output:
Example 2: In this example, the pipe method is called with reject method.
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;" > w3wiki </ h1 > < p > JQuery | deferred.pipe() method </ p > < button onclick = "Beginner();" > click here </ button > < p id = "GFG" ></ p > < script > function Beginner() { var def = $.Deferred(), filter = def.pipe(null, function (val) { return "pipe() is called with " + val; }); def.reject('reject method'); filter.fail(function (val) { $('#GFG_DOWN').append(val); }); } </ script > </ body > </ html > |
Output: