I have the following code:
function getWeather() {
var url = "http://api.openweathermap.org/data/2.5/weather?lat=35& lon=139?jsoncallback=?";
$.getJSON(url, function (data) {
console.log(data.id);
});
}
And according to Firefox I'm getting a missing semicolon error in line 1:8
{"coord":{"lon":139,"lat":35},"sys":{"message":0.0106,"country":"JP","sunrise":1427920171,"sunset":1427965544},"weather":[{"id":800,"main":"Clear","description":"Sky is Clear","icon":"01d"}],"base":"stations","main":{"temp":285.577,"temp_min":285.577,"temp_max":285.577,"pressure":1026.48,"sea_level":1034.31,"grnd_level":1026.48,"humidity":100},"wind":{"speed":5.56,"deg":57.001},"clouds":{"all":0},"dt":1427944893,"id":1851632,"name":"Shuzenji","cod":200}
I can't find the error.
Looks like the said resource is expecting the callback param name as callback
not as jsonpcallback
function getWeather() {
var url = "http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139&callback=?";
$.getJSON(url, function (data) {
console.log(data);
});
}
Demo: Fiddle
Also you can use CORS support
function getWeather() {
var url = "http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139";
$.getJSON(url, function (data) {
console.log(data);
});
}
Demo: Fiddle