Open In App

JQuery deferred.pipe() Method

Last Updated : 15 Nov, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

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=
    </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.

html




<!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:



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads