JQuery deferred.resolve() method

This deferred.resolve() method in JQuery is used to resolve a Deferred object and call any doneCallbacks with the given arguments.
Syntax:

deferred.resolve([args])

Parameters:

  • args: This is optional parameters and is arguments which are passed to the doneCallbacks.

Return Value: This method returns the deferred object.

There are two examples discussed below:

  • Example: In this example, The resolve() is called with the arguments.

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE HTML> 
    <html>  
    <head
        <title
          JQuery | deferred.resolve() method
        </title>
        </script
    </head>   
    <body style="text-align:center;">
        <h1 style="color:green;">  
            GeeksForGeeks  
        </h1
        <p id="GFG_UP"
        </p>
        <button onclick = "Geeks();">
        click here
        </button>
        <p id="GFG_DOWN"
        </p>
        <script
            var el_up = document.getElementById("GFG_UP");
            el_up.innerHTML = "JQuery | deferred.resolve() method";
            function Func(val, div){
              $(div).append(val);
            }
            function Geeks() {
                var def = $.Deferred();
                def.done(Func);
                def.resolve(
    'resolve() method is called with arguments 
               and Deferred object is resolved', '#GFG_DOWN')
            
        </script
    </body>   
    </html>        
         

    chevron_right

    
    

  • Output:
  • Example: In this example, The resolve() is called without arguments.

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE HTML> 
    <html>  
    <head
        <title
          JQuery | deferred.resolve() method
        </title>
        </script
    </head>   
    <body style="text-align:center;">
        <h1 style="color:green;">  
            GeeksForGeeks  
        </h1
        <p id="GFG_UP"
        </p>
        <button onclick = "Geeks();">
        click here
        </button>
        <p id="GFG_DOWN"
        </p>
        <script
            var el_up = document.getElementById("GFG_UP");
            el_up.innerHTML = "JQuery | deferred.resolve() method";
            function Func(){
              $('#GFG_DOWN').append(
    "resolve() method is called without arguments
              and Deferred object is resolved");
            }
            function Geeks() {
                var def = $.Deferred();
                def.done(Func);
                def.resolve()
            
        </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.