Related Articles

Related Articles

JQuery deferred.pipe() Method
  • Last Updated : 14 Jul, 2020

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
Recommended Articles
Page :