我正在尝试向页面添加comment.create
和comment.remove
如果我使用以下内容,一切正常:
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);
}
});
});
};
但是,无论我在哪里添加以下内容,都不会触发,ajax 不会触发,因此没有成功消息
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>