I am facing a challenge in JavaScript as I attempt to create a program that fetches weather information from OpenWeatherMap using JSON. My experience with JSON is limited, but I believe I have a grasp of the underlying concepts. Despite this, when I trigger the "Get JSON" action, nothing seems to occur. It is possible that there is an issue with the "data.temp" parameter within the getJSON function. However, based on my understanding, it should at least display "Temperature:" if functioning correctly. Below are snippets of HTML and JavaScript for reference.
HTML:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"> </script>
<div id = "owmData" style = "background-color:#cc0;">
Weather data will be shown here.
</div>
Get JSON
JavaScript:
$(document).ready(function() {
/* Perform operation upon clicking the "getIt" button.*/
$("#getIt").click(function(event){
/* Variable to store weather details.*/
var weatherNow="http://api.openweathermap.org/data/2.5/weather?q=London,uk&callback=test&appid=******************";
$.getJSON(weatherNow,function(data){
$('#owmdata').append('<p>Temperature : ' + data.temp+ '</p>');
});
});
});