I want to fetch the latest local weather details using a weather API. Below is the code I am working with:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
function generateUrl() {
var api = "http://api.openweathermap.org/data/2.5/weather?q=";
var city = "PUNE,IN";
var units = "&units=metric";
var appid = "&APPID=**************************"
var cb = "&callback=JSON_CALLBACK";
return (api + city + units+ appid + cb);
}
$.getJSON(generateUrl(), function(result) {
$.each(result, function(id, val) {
//document.write(val);
//document.getElementById('ModifyMe').innerHTML = '<a id ="'+id+'">'+val+'</a>';
$("div").append(val + " ");
});
});
</script>
<div id = 'ModifyMe'><div>
My query: How can I retrieve the JSON data from the URL generated by the generateUrl() function?