本文介绍了喜欢使用FB API和JQuery的照片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,想使用JQuery喜欢一张照片。我试过.post,.ajax,现在使用FB.api文章。当我运行脚本时,我甚至不会收到错误消息。这是我点击喜欢按钮时的功能:

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();
            }
        }
    });
}

任何建议将是一个很好的帮助,因为我一直在搜索FB api docs几个小时!!

Any suggestions would be a great help as I've been searching through the FB api docs for hours!!

推荐答案

我想出来,我不得不写功能在parse-time被定义比运行时(格式化问题)

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();
            }
        }
    });
}

这篇关于喜欢使用FB API和JQuery的照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 10:10