Problem with GET from api

Hello,

i am having a problem with loading data from an api. I am working on weather app.
I am using opernweather api. The problem is with getting JSON data. Here is the jQuery code:

    var longitude = 46.0553;
    var latitude = 14.5144;
    var apikey = /* my openweather apikey */;

    var url = 'api.openweathermap.org/data/2.5/weather?lat='+ latitude +'&lon='+ longitude+ '&APPID=' + apiKey;

    $.getJSON(url, function(result){
        console.log(result);
    })

The response i get is:

Cannot GET /weather%20app/api.openweathermap.org/data/2.5/weather?lat=46.0553&lon=14.5144&APPID={apikey}

But if i use this URL directly in a browser it works fine…

So apparently the problem is I am developing this app locally running on the server by my editor. I used Chrome for testing, but it has something called same origin policy. Atm for local testing I am using firefox developer edition and works fine now. So after a total of 2 hours, finally. Ahhh the life of a newbie.

I’m not sure how that code could work find anywhere - you spell it apikey in one place and apiKey in the other.

I think OWM started clamping down because they were getting bombarded with API requests from FCC users. Plus, these sites change from time to time so it’s hard to keep up. And CORS problems are a big issue with AJAX and I’m sure there is some way to fix it, but I am too tired to deal with it right now.

Because of these problems, FCC created it’s own API:

var url = "https://fcc-weather-api.glitch.me/api/current?lat=" +
        latitude +
        "&lon=" +
        longitude;

That should work fine for you.