jQuery deferred.reject() Method

The deferred.reject() method in jQuery is used to reject a Deferred object and call any failCallbacks with the given arguments.

Syntax:

deferred.reject( [args] )

Parameters:

  • args: It is an optional parameter that are passed to the failCallbacks.

Return Value: This method returns the deferred object.

Example 1: In this example, the reject() method is called with the arguments.



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.reject() 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('reject() method is '
                + 'called with arguments and'
                + ' Deferred object is '
                + 'rejected', '#GFG')
        
    </script>
</body>
  
</html>

chevron_right


Output:

Example 2: In this example, the reject() method is called without arguments.

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.reject() method
    </p>
  
    <button onclick="Geeks();">
        click here
    </button>
  
    <p id="GFG"></p>
  
    <script>
        function Func() {
            $('#GFG').append
                ("reject() method is called "
                + "without arguments and "
                + "Deferred object is rejected");
        }
          
        function Geeks() {
            var def = $.Deferred();
            def.fail(Func);
            def.progress(Func);
            def.reject()
        
    </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.