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.
If you take a look at the getJSON documentation, you will see that it is the same as using:
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.
Worked out for me. Thanks @RandellDawson you’re the best!