James Earlywine James Earlywine - 1 year ago 105
Javascript Question

jQuery deferred.notify not working

I want to use the jQuery Promise Library/API. I wrote tidbit of code to test/learn it, but I'm not getting the expected results.

I paste this code into my javascript console:

window.dfd = $.Deferred();

function(status) {console.log('resolved, status: ', status);},
function(status) {console.log('rejected, status: ', status);},
function(status) {console.log('notified, status: ', status);}

At this point, I would expect


to trigger the 3rd callback and log to console - but it doesn't.

These both give the expected result:


Does anyone know why I'm not getting the expected notify result? - and/or what I can do differently to get the expected result?

Answer Source

It works fine for me James, maybe it is the order you are calling resolve, reject or notify.

Once you resolve or reject a deferred, you can't notify it anymore.

If you try your code as it is and do something like:


You should see the expected income.

Once you resolve or reject, you don't see notifications anymore so:

window.dfd.notify('hello'); //this won't log anything
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download