Ensure jquery and FB JS SDK are both initialized
I am using the FB.ui method to publish something to the users wall and want to capture whether the user published or cancelled. To do this I am calling a开发者_如何学Go function (say bi_published(){...}) which updates a table in the db which is being used to capture metrics. It does this by making a $.ajax call. The issue is bi_published has to be within $(function() {}); to ensure $ is initialized. but then when I call this from within the FB.ui then I get the error bi_published() is not defined. If I keep it outside then I get $ is not defined.
FB.ui is called in the following manner.
fbEnsureInit(function(){
FB.ui({ method: 'stream.publish', other params}, function(response){ if(response && response.post_id){bi_published();}else{bi_not_published();}});
});
technique explained here: How to detect when facebook's FB.init is complete
What should be done in such a scenario?
So I figured out how to achieve this.
I now put bi_published outside and then within that method I put $(function(){ making ajax call here})
Works fine.
So simple I kinda feel stupid.
精彩评论