未定义JSONP API回调

时间:2017-05-07 09:19:29

标签: jsonp

我试图从此API中获取随机引号 - http://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1&_jsonp=mycallback

https://quotesondesign.com/api-v4-0/

上的API文档

来自控制台的错误消息:未捕获的ReferenceError:未定义mycallback。我该如何解决这个问题?我的代码如下。任何帮助表示感谢,谢谢!

 $(document).ready(function(){
    function getNewQuote(){
        $.ajax({
            method: 'GET',
            url: 'http://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1&_jsonp=mycallback',
            jsonp: 'jsonp',
            dataType: 'jsonp'
        }).done(function(data){
            console.log(data);
    });
}

    getNewQuote();
    });

1 个答案:

答案 0 :(得分:1)

您需要在$(document).ready()之外创建回调 像这样:

var mycallback = function (a) {
    console.log(a);
};
相关问题