Can anyone tell me why this isn't working for me?
Example page here
.html
window.fbAsyncInit = function() {
FB.init({appId: '194189377275548', status: true, cookie: true,
xfbml: true});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
function catchCommentAdd()
{
$.ajax({
type: "POST",
url: "ajaxCommentCount.php",
data: "id=<?php echo $_GET['id']; ?>&direction=up",
dataType: "json"
});
return true;
}
function catchCommentDelete()
{
$.ajax({
type: "POST",
url: "ajaxCommentCount.php",
data: "id=<?php echo $_GET['id']; ?>&direction=down",
dataType: "json"
});
return true;
}
FB.Event.subscribe('ments.create', function(response) {
alert(response);
catchCommentAdd();
});
Can anyone tell me why this isn't working for me?
Example page here
http://totalmunitycollegemove./post-438.html
window.fbAsyncInit = function() {
FB.init({appId: '194189377275548', status: true, cookie: true,
xfbml: true});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
function catchCommentAdd()
{
$.ajax({
type: "POST",
url: "ajaxCommentCount.php",
data: "id=<?php echo $_GET['id']; ?>&direction=up",
dataType: "json"
});
return true;
}
function catchCommentDelete()
{
$.ajax({
type: "POST",
url: "ajaxCommentCount.php",
data: "id=<?php echo $_GET['id']; ?>&direction=down",
dataType: "json"
});
return true;
}
FB.Event.subscribe('ments.create', function(response) {
alert(response);
catchCommentAdd();
});
Share
Improve this question
edited Feb 27, 2011 at 3:56
ifaour
38.1k12 gold badges73 silver badges79 bronze badges
asked Feb 27, 2011 at 1:43
AndrewAndrew
4211 gold badge5 silver badges11 bronze badges
2
-
Try removing the
alert()
also try removing the like and the Fan-box to the right just to check... – ifaour Commented Feb 27, 2011 at 4:14 - I found out thanks to the dude below that the event doesnt fire unless you have the href attribute defined with the url of the page. – Andrew Commented Mar 3, 2011 at 7:32
4 Answers
Reset to default 4i had the same problem but maybe found a solution (works on my test-site). It seems that the event name "ments.create" is wrong. The correct (or at least working) event is "ment.create" (without the s)
Here is my code-snippet:
<script>
window.fbAsyncInit = function() {
FB.init({
appId: 'APP_ID',
status: true,
cookie: true,
xfbml: true
});
FB.Event.subscribe('ment.create', function(response) {
alert(response.mentID);
});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol + '//connect.facebook/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
<fb:ments href="YOUR_URL" num_posts="5" width="500" ></fb:ments>
Use "ment.create" and not "ments.create" it's singular.
This code:
FB.Event.subscribe('ments.create',
function(response) {
alert(response);
catchCommentAdd(); });
Relies on Facebook's Javascript SDK having already loaded in. Because that happens asynchronously, you should place the code in your window.fbAsyncInit function, following the FB.init call:
window.fbAsyncInit = function() {
FB.init({appId: '194189377275548', status: true, cookie: true,
xfbml: true});
FB.Event.subscribe('ments.create', function(response) {
alert(response);
catchCommentAdd();
});
};
You read Facebook's documentation? That's a big mistake unfortunately.
Try with ments.add instead of ments.create...