Search code examples
jquerycallbackpromisejquery-deferredjquery-callback

How to Determine if There Are Any Un-Resolved Promises, Deferreds or Callbacks using jQuery?


Is there way to determine if there are any unsolved promises, deferreds or callbacks in jQuery? We have a large single-page JavaScript application that is hanging on $(document).ready(). For debugging purposes we would like to see if we missed calling a callback or resolving a promise or deferred to see if that might be affecting .ready().


Solution

  • Two pieces of good news :

    1. jQuery and Deferreds and Promises both have a state() method that returns "pending", "resolved" or "rejected".
    2. Nothing you do with jQuery promises will inhibit firing of the event underlying $(document).ready().

    Bad news - you still have an issue that needs fixing.

    Without seeing the code (preferably a minimal example that exhibits the issue), it's impossible to say what the cause might be.

    First thing to do is look in your browser's console to see if it shows some sort of error.