Cant get JSON from wheater api

https://codepen.io/xd/pen/ZKYYEN?editors=1111

any suggestions? thank you

There’s a couple of problems. First, your endpoint URL needs to be fully qualified, which means including the protocol at the beginning.

$.get("http://api.openweathermap.org/data/2.5/weather?lat=" + lati + "&lon=" + long + "...")

Second, even with your URL set, you’re going to run into cross domain issues. This can be solved quickly by using a CORS proxy. Add https://cors-anywhere.herokuapp.com/ to the beginning of your URL.

$.get("https://cors-anywhere.herokuapp.com/http://api.openweathermap.org/data/2.5/weather?lat=" + lati + "&lon=" + long + "...")

Make sure you’re always connecting to CodePen via HTTPS.

1 Like