Failing to call openweatherapp API : what am I missing?

Here is the code from the codepen

Not sure why the “lat” variable is not updated after I call the API…

  var api ="";
  var lat = "lat_initial";

  $.getJSON(api, function(data){
    alert("JSON OBTAINED!");
    lat =;

  $(".getLatBtn").on("click", function(){
    alert("BUTTON PUSHED!");

Since June 1, all Codepens are served over HTTPS.

Because of CORS, your ajax call needs to get data from a HTTPS endpoint.
(More info:

Your var api needs to be instead of

This way the content will be fetched from a HTTPS endpoint and your var lat will display the correct latitude.

1 Like