Sebastian Sebastian - 6 months ago 35
Javascript Question

I Can't get data from JSON file - $.getJSON doesn't work

https://codepen.io/RycerzPegaza/pen/pbzdgY
This is my codepen where I try to get data from a weather API. The link providing JSON data works, but none of what do here works:

$.getJSON(temperature, function(data) {
cityName.innerHTML = data;
});


-If i change data to a test string it doesn't work either.
- "$.get" doesn't work either

Answer

It's not an error with $.getJSON,just open the console of you bowser you will see this error.

jquery-2.2.4.min.js:4Mixed Content: The page at 'https://codepen.io/RycerzPegaza/pen/pbzdgY?editors=1111' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://api.openweathermap.org/data/2.5/weather?lat=31.277204800000003&lon=121.538243&APPID=7248ea2cccd4e2cd9b65fa7bd9cf6e9a&units=metric'. This request has been blocked; the content must be served over HTTPS.

This is because the API provide by http but you page run in https,this will cause a security hole, so the bowser block the request.

Comments