Open In App

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:

Return Value: This method returns the deferred object.



Example 1: In this example, the pipe method is called with resolve method.




<!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(),
                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.




<!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(),
                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:


Article Tags :