Facebook fbAsyncInit firing twice
        Posted  
        
            by 
                JoelD
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by JoelD
        
        
        
        Published on 2011-01-03T05:52:19Z
        Indexed on 
            2011/01/03
            5:53 UTC
        
        
        Read the original article
        Hit count: 271
        
I'm using Facebook's Javascript SDK to allow login/logout, and my problem is that when I use their window.fbAsyncInit call to initiate the FB session, it always fires twice. I've included a simplified code sample. I'd appreciate any help!
<html><head>
<script type="text/javascript">
...some of my own functions, not related to Facebook...
</script>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
    FB.init({
      appId   : '<?php echo FACEBOOK_APPID; ?>',
      session : <?php echo json_encode($session); ?>, status:false, cookie:true,  xfbml: true 
    });
    alert("1");
    FB.getLoginStatus(function(response) {
        if(response.session) { ...do stuff... } else { ...do other stuff...}
    });
};
alert("2");
</script>
...page contents...
</body></html>
The "2" alert fires a single time, and then the "1" alert fires twice.
© Stack Overflow or respective owner