Getting problem in random quote generator

Getting problem in random quote generator
0

#1

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

function randomQuote() {
  $.ajax({
      url: "http://api.forismatic.com/api/1.0/?",
      dataType: "jsonp",
      data: "method=getQuote&format=jsonp&lang=en&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();
  $("button").click(function(){
  randomQuote();
});
});

#2

@ran91 please post a link to a codepen with your code and I’ll be glad to help you


#3

@jenovs answered to you 7 hours ago but you never replied to him.

You can find his reply here.

Unless it’s not the same code? But apparently it was working ?


#4

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.


#5

The link is …https://codepen.io/ran91/pen/YpJmYM


#6

@ran91 Your code has one problem, you have mixed _ and -. You have defined the id as random_quote but your html is being outputted to random-quote. Also, instead of using $(“button”).click(), give your button a unique id/class (because there are two buttons)


#7

Also, do not use https while using codepen if you are using any url containing http in your code, use http instead. Google “mixed content”.


#8

thank u …Finally it has started to work and I have finished my project