getJSON no output?
-
07-06-2021 - |
Question
I can't for the life of me figure out why this is not working?
<div class="clouds">
</div>
<div class="station">
</div>
<script type="text/javascript">
$.getJSON("http://api.geonames.org/findNearByWeatherJSON?lat=53.36652&lng=-2.29855&username=jolones&callback=?",
function(data){
var clouds = data.weatherObservation.clouds;
var station = data.weatherObservation.stationName;
jQuery.(".clouds").html(clouds);
jQuery.(".station").html(station);
});
Much appreciation
Solution
jQuery . (".clouds").html(clouds);
jQuery . (".station").html(station);
Do you mean to have those dots there? Should be
jQuery(".clouds").html(clouds);
jQuery(".station").html(station);
OTHER TIPS
Browser security policy prevents you from making json ( xmlhttpReqeusts ) to another domain. You should lookup how JSONP works though, this may be useful if geonames.org provides a jsonp method ( jsonp would allow you to do this and call another domain ).
Another option is to create a local php script that calls the api remotely. PHP is not prohibited to call a remote api, so you could use php to retrieve the json results and then use javascript to retrieve the results from your local ( on same domain ) php program.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow