2

I'm trying to make a simple weather app and it seems I can't access any information using my variable for the JSON-link. Heres my code:

$(document).ready(function() {
    var key = 'a91a892f1f2a1aa3f7409a78f72af675';
    var locationURL = 'http://ip-api.com/json';
    var longitude;
    var latitude;

    //Getting the geolocation from the user
    $.getJSON(locationURL, function(data) {
        longitude = data.lon;
        latitude = data.lat;
        var url = 'api.openweathermap.org/data/2.5/weather?lat=' + latitude + '&lon=' + longitude + '&appid=' + key;
        console.log(url);
        $.getJSON(url, function(data2){
            console.log(data2, url);
        });

    });
});

But I get no return from the second JSON-call, and it seems like the variable 'url' is broken or something. What am I doing wrong or not seeing here?

1
  • You should always check the Javascript console for errors before posting here. If you had, it might have helped you solve the problem yourself, or at least post a more complete question. Commented Feb 27, 2017 at 20:32

2 Answers 2

3

You're missing protocol:

var url = '//api.openweathermap.org/data/2.5/weather?lat=' + latitude + '&lon=' + longitude + '&appid=' + key;
Sign up to request clarification or add additional context in comments.

Comments

0
get: function(req, data, callback) {
    data.gym_hash = this.gym_hash;
    console.log(data);

    $.ajax({
        url: rest.server + req,
        type: 'GET',
        data: data,

        success: function(result) {
            callback(result);
        }
    });
}

I use this type if code and let js and jQuery do the magic of formatting the parameters into the url. Call is like this:

       get(
        "Path/To/Rest",
        {
            email: email,
            password: password,

        },
        function(result){console.log(result);});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.