Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using fb.api calls with jquery deferred

I just cannot get my head around deferred objects

dfd = new $.Deferred();
FB.api('/me/posts?fields=id,story&access_token='+accessToken,function(response){          
    dfd.resolve();  
    //Do something with the result  
});
dfd.done(alert(dfd.isDeferred()));

From my understanding the .done should only fire once the request is completed and the callback sets the object as resolved, however the alert box is firing false before the request completes.

What am I missing?

like image 454
Matthew Dolman Avatar asked Nov 27 '11 10:11

Matthew Dolman


1 Answers

Try changing the last line of code to :

dfd.done(function(){ alert(dfd.isDeferred()); });

This is how the use of the done() function is documented in the jQuery API

like image 188
Lix Avatar answered Oct 25 '22 17:10

Lix