简单的$ .getJSON(“地址”),功能(res){不会

时间:2016-11-14 21:30:23

标签: javascript jquery facebook facebook-graph-api

我有一个简单的功能:

setInterval(function () {
    $.getJSON("https://graph.facebook.com/v2.8/?ids=1234567_1234567&fields=reactions.type(LIKE).limit(0).summary(total_count).as(reactions_like)%2Creactions.type(LOVE).limit(0).summary(total_count).as(reactions_love)&access_token=thatsmytoken"),
        function (res) {

            console.log(res);

        };
}, 5000);

所以它应该调用GET并在控制台中显示结果,但它不是...... 我可以在Chrome中看到网络信息中的GET结果(每5秒就可以正常工作)但是它不会进入函数内部(res)

为什么?

1 个答案:

答案 0 :(得分:0)

您的括号不正确。它应该是:

setInterval(function () {
    $.getJSON("https://graph.facebook.com/v2.8/?ids=1234567_1234567&fields=reactions.type(LIKE).limit(0).summary(total_count).as(reactions_like)%2Creactions.type(LOVE).limit(0).summary(total_count).as(reactions_love)&access_token=thatsmytoken",
        function (res) {

            console.log(res);

        });
}, 5000);

现在,如果成功,function(res){...}将成为getJSON函数的回调。有关回调的详细信息,请单击here