Getting problem to connect with random quote generator API

when Iam clicking the button , it is not showing any result.
here is my js code

function randomQuote() {
dataType: "jsonp",
success: function( response ) {
$("#random_quote").html("<p id='random_quote' class='text-center'>" +
response.quoteText + "<br/>&dash; " + response.quoteAuthor + " &dash;</p>");
$(document).ready(function() {randomQuote();
1 Like

I just tried your code and it works. Show the whole code.
If you are writing the code in Codepen make sure that you have added jQuery in JS settings.

I am giving you my codepen link

You’ve apparently fixed it on your own already. Works for me.
One minor thing: In your twitter function where you add the quotation marks, you might want to add a space so the author name does not come directly after the closing quotation mark. Like so: + '" ' +.

1 Like

ok…Thank you …I will fix it.

Hi, it looks like your problem is fixed, but I have a question because I am using the same API ( for the quote generator. How did you know to structure part of your data in ajax as “jsonp=?” ? I was stuck on this until I saw your solution because I was using the data like this: “callback=?” and not “jsonp=?”.

I kept getting a syntax error even though other sources told me to use “callback=?” at the end of a JSONP request. Thanks for any insight.

I got the idea of this from here


Very good resource. Thanks, and good luck coding!

1 Like

I am having the same problem. Quotes are not getting displayed . My code is:

$(document).ready(function() {
var randomQuote;
var randomAuthor;
function getQuote() {
var url = "";

$.getJSON(url, function(data) {
  $(".author").html("~" + data.quoteAuthor);
  randomQuote = data.quoteText;
  randomAuthor = data.quoteAuthor;

$("#newQuote").on(“click”, function() {

$("#tweet").on(“click”, function() {“
+randomQuote + " ~" + randomAuthor);

Thank you very much. It worked.
The problem was with s. It should have been https instead of http. but what is exactly it means, i don’t get it. Can you eleborate a bit?

Thanks for the explanation. This was new to me.