Weather App - How to assign the JSON object data values outside the AJAX call function after the AJAX call has been performed?

Right now I am having trouble assigning the latitude and longitude data values from the JSON object from ip-api.com to the variables “latitude” and “longitude”. When I did a console.log inside the function display_Lat_Lon, the latitude and longitude variables returned the correct values. However, outside of that function, the latitude and longitude variables are empty. As a result, the url for openweather.com isn’t displaying the latitude and longitude values inside of it.

How do I set the variables longitude and latitude to the correct values after the AJAX call to ip-api.com has been performed?

what i did is create a function for the the openWeather part … then in your function display_lat_lon
under the last console.log(longitue) place a call for your function passing it the latitude and longitude

     ......
 ......
console.log((longitude);
displayWeather(latitude, longitude); // This the function you create
}```

the function you create called eg displayWeather  cant run until your display_lat_lon calls it and passes it the paramaters ... so when its called it has the required info you need

so put all your openWeather code in the displayWeather function and your sorted.
1 Like

Fixed it. It works! Thanks.