2012-11-21 46 views
0

我想補充comment.createcomment.remove到頁面多FB.Event.subscribe不會閃光,但單不

如果我用下面的,一切正常:

window.fbAsyncInit = function(){ 
    FB.Event.subscribe('comment.create', function(response){ 
    $.ajax({ 
    type: "POST", // form method 
    url: "/pages/includes/add_fb_comments.php",// destination 
    data: "url=" + encodeURIComponent(response.href) + "&id=<?=$id?>&action=add", 
    cache: false, 
    success: function(){ 
    alert('Success' + encodeURIComponent(response.href) + response.commentID); 
    } 
    }); 
    }); 
    }; 

但是,然而何我添加以下,無火災,阿賈克斯不火,因此沒有成功的消息

FB.Event.subscribe('comment.remove', function(response){ 
    $.ajax({ 
    type: "POST", // form method 
    url: "/pages/includes/add_fb_comments.php",// destination 
    data: "commentID=" + response.commentID + "&action=remove", 
    cache: false, 
    success: function(){ 
    alert('removed comment: ' response.commentID); 
    } 
    }); 
}); 

我一樣window.fbAsyncInit = function(){我內都嘗試已經試過了分開window.fbAsyncInit = function(){我甚至嘗試完全分開<script></script>但他們根本不開火。

這是一個已知的問題?我不能相信這是肯定這些總是存在在一起

任何想法?

這是完全實際的代碼我試圖:

<div class="fb-comments" data-href="<? echo curPageURL(); ?>" data-num-posts="4" data-width="578" mobile="false"></div> 
     <script> 
      window.fbAsyncInit = function(){ 
        FB.Event.subscribe('comment.create', function(response){ 
         $.ajax({ 
          type: "POST", // form method 
          url: "/pages/includes/add_fb_comments.php",// destination 
          data: "url=" + encodeURIComponent(response.href) + "&id=<?=$id?>&action=add", 
          cache: false, 
          success: function(){ 
          alert('Success' + encodeURIComponent(response.href) + response.commentID); 
          } 
         }); 
        }); 
      }; 

      window.fbAsyncInit = function(){ 
        FB.Event.subscribe('comment.remove', function(response){ 
         $.ajax({ 
          type: "POST", // form method 
          url: "/pages/includes/add_fb_comments.php",// destination 
          data: "commentID=" + response.commentID + "&action=remove", 
          cache: false, 
          success: function(){ 
          alert('removed comment: ' response.commentID); 
          } 
         }); 
        }); 
      }; 
      </script> 

回答

0

每個window.fbAsyncInit被設置相同的屬性,因爲這些都是順序執行的,而不是累積性的,只有最後一個函數實際上是設置。

現在,我敢肯定你還有第三個fbAsyncInit =...區塊,其中SDK已初始化並且全部都是,並且由於上述情況永遠不會執行。

將所有這一切移到一個fbAsyncInit,你應該很好。