开发者

Ensure jquery and FB JS SDK are both initialized

开发者 https://www.devze.com 2023-01-19 16:21 出处:网络
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(){..

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消