问题
I am having a problem trying to 'like' a photo using JQuery. I've tried .post, .ajax, and now using the FB.api post. When I run the script I don't even get the error messages. This is what I have as a function when the 'like' button is clicked:
function like(postId) {
FB.api('/'+postId+'/likes', 'post', function(result) {
if (!result) {
alert('Error: No Response');
} else if (result.error) {
alert('Error: '+result.error.message+'');
} else {
if (result==true) {
$('#likeButton-'+postId).hide();
$('#unlikeButton-'+postId).show();
}
}
});
}
Any suggestions would be a great help as I've been searching through the FB api docs for hours!!
回答1:
I figured it out, I had to write the function to be defined at parse-time rather than run-time(as the question is formatted)
like = function(postId) {
FB.api('/'+postId+'/likes', 'post', function(result) {
if (!result) {
alert('Error: No Response');
} else if (result.error) {
alert('Error: '+result.error.message+'');
} else {
if (result==true) {
$('#likeButton-'+postId).hide();
$('#unlikeButton-'+postId).show();
}
}
});
}
回答2:
Try this:
function like(postId) {
FB.api('/'+postId+'/likes', 'post', function(result) {
console.dir(results);
});
}
And check your browser's console for the complete object and let us know what you see.
Also use your browser's network sniffer to check to see the Response content of the api call.
来源:https://stackoverflow.com/questions/8921870/liking-a-photo-using-fb-api-and-jquery