我有这段代码:
$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
文件来发送电子邮件。
我已将代码放在drupal的facebook_comments_module
模块的facebook_comments
文件中。 (我的网站是一个drupal网站)
答案 0 :(得分: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>';`