GET request does not receive data in codef, but works in browser tab

This is my codepen for a simple weather app I made a long time ago. However, it does not work now. When I insert the tab api

into the browser, I get the data, but in codeden it doesn't work.

var api = "http://api.openweathermap.org/data/2.5/weather?
q=Lam%20Tin,HK&appid=23a5271ef6a94716ac17ec27e9f4bcd8";
$.getJSON(api, function(data) {
  console.log(data);
});

      

+3


source to share


1 answer


Mistake

The page at 'https://codepen.io/iamanoopc/pen/JEjYKR?editors=0011' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://api.openweathermap.org/data/2.5/weather?q=Lam%20Tin,‌​HK&appid=23a5271ef6a‌​94716ac17ec27e9f4bcd‌​8'. This request has been blocked; the content must be served over HTTPS.

      

Explanation

enter image description here

as shown very clearly. HTTPS, but requested an insecure XMLHttpRequest

.Is a secure domain server https

. Your http call is not secure. For security reasons they will block your requestThis request has been blocked; the content must be served over HTTPS



Alternative

Try with insecure http

snippet of domain server like jsbin

enter image description here

Demo withJsbin

+2


source







All Articles