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

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE HTML>
<html>
  
<head>
    <script src=
    </script>
</head>
  
<body style="text-align:center;">
    <h1 style="color:green;">
        GeeksForGeeks
    </h1>
  
    <p>
        JQuery | deferred.pipe() method
    </p>
  
    <button onclick="Geeks();">
        click here
    </button>
      
    <p id="GFG"></p>
  
    <script>
        function Geeks() {
            var def = $.Deferred(),
                filtr = def.pipe(function (val) {
                    return "pipe() is called with " 
                                + val;
                });
  
            def.resolve('resolve method');
            filtr.done(function (val) {
                $('#GFG').append(val);
            });
        
    </script>
</body>
  
</html>

chevron_right


Output:

Example 2: In this example, the pipe method is called with reject method.

html

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE HTML>
<html>
  
<head>
    <script src=
    </script>
</head>
  
<body style="text-align:center;">
    <h1 style="color:green;">
        GeeksForGeeks
    </h1>
  
    <p>
        JQuery | deferred.pipe() method
    </p>
  
    <button onclick="Geeks();">
        click here
    </button>
  
    <p id="GFG"></p>
  
    <script>
        function Geeks() {
            var def = $.Deferred(),
                filtr = def.pipe(null, 
                        function (val) {
                    return "pipe() is called with "
                            + val;
                });
            def.reject('reject method');
            filtr.fail(function (val) {
                $('#GFG_DOWN').append(val);
            });
        
    </script>
</body>
  
</html>

chevron_right


Output:




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.