Open In App

jQuery deferred.progress() Method

Last Updated : 24 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

This deferred.progress() method in jQuery is used to add handlers which are to be called when the Deferred object generates progress notifications.

Syntax:

deferred.progress(progressCallbacks[, progressCallbacks])

Parameters:

  • progressCallbacks: This parameters is a function, or array of functions, which are to be called when the Deferred generates progress notifications.
  • progressCallbacks: It is an optional parameters and is a function, or array of functions, which are to be called when the Deferred generates progress notifications.


Return Value: This method returns the deferred object.

Example 1: In this example, The progress() method is called with the 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;">
        GeeksForGeeks
    </h1>

    <p>
        jQuery | deferred.progress() method
    </p>

    <button onclick="Geeks();">
        Click Here
    </button>

    <p id="GFG"></p>

    <script>
        function Func(val, div) {
            $(div).append(val);
        }
        function Geeks() {
            var def = $.Deferred();
            def.fail(Func);
            def.progress(Func);
            def.reject('"Func" is added as '
                + 'progressCallbacks using '
                + 'progress() method when '
                + 'Deferred object is rejected',
                '#GFG')
        } 
    </script>
</body>

</html>

Output:

jQuery-deferredprogress()-method-

Example 2: In this example, the progress() method is called with the 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;">
        GeeksForGeeks
    </h1>

    <p>
        jQuery | deferred.progress() method
    </p>

    <button onclick="Geeks();">
        Click Here
    </button>

    <p id="GFG"></p>

    <script>
        function Func(val, div) {
            $(div).append(val);
        }
        function Geeks() {
            var def = $.Deferred();
            def.done(Func);
            def.progress(Func);
            def.resolve('"Func" is added as '
                + 'progressCallbacks using '
                + 'progress() method when '
                + 'Deferred object is resolved',
                '#GFG')
        } 
    </script>
</body>

</html>

Output:

jQuery-deferredprogress()-method----2


Next Article

Similar Reads