Stuck in local weather app project

here is my JS code and err info. the location name can be show. but the result can not show weather information. I do not know how to solve it. please help me. :sleepy::tired_face:

$(document).ready(function () {
var lat;
var lon;

$('#location').text('loading . . .');
function getLocation() {
    url: '',
    method: 'GET',
    dataType: 'jsonp',
    jsonpCallback: 'callback',
    success: function (response) {
      $('#location').text( + ',' +;
      lat = response.latitude;
      lon = response.longitude;
function getWeather(lat, lon) {
        url: '' + lat + '&lon=' + lon,
        method: 'GET',
        dataType: 'JSON',

        success: function (data) {

getWeather(lat, lon);


Hi @metrical1

This is a classic issue that newer JS developers will run into due the asynchronous nature of ajax requests.

I definitely recommend researching JS and ajax asynchronous behavior, I just googled but this article might be a good start:

Essentially, the data from getLocation() won’t have been processed before the call to getWeather(), so when getWeather tries to access the lat and lon values, they will be undefined.

Try calling getWeather from within the success function of the getLocation ajax call and passing the lat/lon you get from the response.

Hello @joesmith100

Thank you! Now I got the correct result. I appreciate you!:rofl: