Search code examples
javascriptjsonajaxgetjson

getJSON works for some addresses, but not others


Having a strange problem. I'm using getJSON to retrieve information online using the following code:

$.getJSON("url", function(json) {
      $("#quote").html(JSON.stringify(json));
});

Strangely, I have only been able to get the above code to work when I use https://api.whatdoestrumpthink.com/api/v1/quotes/random as the source. All other sources I have tried, such as http://quotes.rest/qod.json do not seem to return anything. I am currently using codepen to make my page.

I can retrieve quotes from the first URL perfectly and access everything how I'd like to, but not with anything else. I have tried using Get and ajax methods as well but to no avail. I'm relatively new to code so there must be something obvious I'm missing?

Thanks for any help.


Solution

  • Looks like the server uses https protocol. Correct the URL and try again. Or provide logs if in case the request fails.