0

我有这个代码:

$output = '<div id="fb-root"></div>
<script> window.fbAsyncInit = function() {
FB.init({
  appId      : "xxx",   
  status     : true,        
  cookie     : true,        
  oauth      : true,       
  xfbml      : true  
});

$(window).load(function(){
    FB.Event.subscribe("comment.create", function(response) {
        var data = {
            action: "fb_comment",
            url: "xxx.com"
        };
     $.post( "mail.php", data );`

   });
});
};

(function(d, s, id) {
 var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, "script", "facebook-jssdk"));</script>

<div class="fb-comments" data-href="'. $url .'" data-num-posts="'. $amount .'" data-notify="true" data-width="'. $width .'" data-colorscheme="'.$style.'"></div>';

然后是文件中的发送电子邮件代码mail.php。(此代码有效)

我认为问题出在FB.Event.subscribe代码上,我不知道如何mail.php仅在发布评论时调用文件来发送电子邮件。

我已将代码放在drupalfacebook_comments_module的模块文件中。facebook_comments(我的网站是一个drupal网站)

4

1 回答 1

0

这有效:

    `$output = '<div id="fb-root"></div>

     <script> window.fbAsyncInit = function() {
FB.init({
  appId      : "xxx",   
  status     : true,        
  cookie     : true,        
  oauth      : true,       
  xfbml      : true  
});

    /* All the events registered */
  FB.Event.subscribe("comment.create", function(response) {

var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}

xmlhttp.open("GET","../xxx/mail.php?response1="+ response.href,true);
xmlhttp.send();
});
 };

  (function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) {return;}
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js";
  fjs.parentNode.insertBefore(js, fjs);
}(document, "script", "facebook-jssdk"));</script>
<div class="fb-comments" data-href="'. $url .'" data-num-posts="'. $amount .'" data-      notify="true" data-width="'. $width .'" data-colorscheme="'.$style.'"></div>';`
于 2013-08-05T10:57:34.873 回答