Random Quote Machine - API

Random Quote Machine - API
0

#1

Could you tell me why this code doesn’t work for me?

$document().ready(function(){
  console.log( "document loaded" );
  var quote, author;
  
  function getNewQuote(){
    $.ajax({
      url: "http://api.forismatic.com/api/1.0/",
      jsonp: "jsonp",
      dataType: "jsonp",
      //data: "method=getQuote&format=jsonp&lang=en&jsonp=?"
	  data: {
        method: "getQuote",
        lang: "en",
        format: "jsonp"
      },
      success: function(res){
        //console.log(res);
        quote = res.quoteText;
        author = res.quoteAuthor;
        
        $('#quote').text(quote);
      }
    });
  }
  getNewQuote();
  
});

#2

I do not mind helping you out, but it would be best if you ask your question on the forum, so that others can learn from the multiple responses you could receive for your question.

If it is OK with you, I can simply move this question to the Help section on the forum, so you do not have to recreate another thread.

I will definitely respond to your question once it is posted in the main forum.

Also, you might want to be more specific on exactly what you are expecting the code to do and then what is happening instead. It helps others to isolate the problems faster.


#3

Thank you for your quick response. It’s ok with me if you move the question to the appropriate forum. Thanks!


#4

#5

You have two issues:

  1. You accidentally wrote $document().ready instead of $(document).ready

  2. You need to use the https prefix on the url instead of http, because since Codepen using https (secure connection), the browser expects you to make requests to another secure connection.


#6

Thank you very much!