Random quotes generator

I’m trying to do the random quotes generator with Ajax call.
Here is my pen: https://codepen.io/thiduck/pen/POoKKN?editors=0011#0

Unfortunately, It doesn’t work (The on click event works - but the AJAX call doesn’t look to be working).

Also, Why can’t I simply use $.getJSON? Why do I use this elaborate way of AJAX call.

1 Like

If you take a look at the getJSON documentation, you will see that it is the same as using:

  dataType: "json",
  url: url,
  data: data,
  success: success

The reason your code is not working is because you have a “Mixed Content” error showing in the console (Ctrl+Shft+I in Chrome). Codepen serves its pages over https, but since you were making an AJAX call to a url starting with http:, Chrome (and most browsers) do not allow this for security purposes. You can correct this problem by changing the http: to https in your code.

1 Like

Worked out for me. Thanks @RandellDawson you’re the best!