1

I'm trying to get random quotes from this API - http://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1&_jsonp=mycallback.

API documentation at https://quotesondesign.com/api-v4-0/

Error message from the console: Uncaught ReferenceError: mycallback is not defined. How do I get around the problem? My code below. Any help appreciated, thanks!

 $(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
  • the problem is that you are pasting code without understanding it. watch the url you are calling and try to understand what you are asking... Commented May 15, 2017 at 12:52

1 Answer 1

1

You need to create a callback outside of $(document).ready() like this :

var mycallback = function (a) {
    console.log(a);
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.