Hi experts,
I created an HTML web resource to display the weather for the entered city. My HTML has a text box and a button where the user can enter the city.
However, I want my code to pick up the value of the city from address1_city attribute and display the information dynamically. How can I change my code to make it work?
<!DOCTYPE html>
<html>
<head>
<title>Weather API</title>
<script
src="code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
</head>
<body>
<input id="city"></input>
<button id="getWeatherForecast">Get Weather</button>
<div id="showWeatherForecast"></div>
<script type="text/javascript">
$(document).ready(function() {
$("#getWeatherForecast").click(function(){
var city = $("#city").val();
var key = 'xxxxxxxxxxxxxxxxxxxxxxxxxx';
$.ajax({
url: 'api.openweathermap.org/.../weather',
dataType: 'json',
type: 'GET',
data: {q: city, appid: key, units: 'metric'},
success: function(data){
var wf = '';
$.each(data.weather, function(index, val){
wf += '<p><b>' + data.name + "<b><img src=openweathermap.org/.../w"+ val.icon + ".png></p>" +
data.main.temp + '°C' + ' | ' + val.main + ", " +
val.description
});
$("#showWeatherForecast").html(wf);
}
})
});
});
</script>
</body>
</html>
Thanks,
Jon
*This post is locked for comments
I have the same question (0)