I have a modal in my HTML code like this ...
<!-- Modal body -->
<div class="modal-body">
<h6 id="capitalCity" class="modal-sub-header"></h6>
<hr>
<ul class="dem">
<p id="date"></p>
<h4 id="capital"></h4>
<p id="description"></p>
etc...
and my linked JavaScript file function is like this, where it is using AJAX calls to both a PHP file and an API to get information regarding the current weather in a country
function getWeather(countryName) {
const monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
let dateObj = new Date();
let month = monthNames[dateObj.getUTCMonth()];
let day = dateObj.getUTCDate() - 1;
let year = dateObj.getUTCFullYear();
let todaysDate = `${month} ${day}, ${year}`;
document.getElementById('date').textContent = todaysDate
$.ajax({
url: "assets/geojson/countryBorders.geo.json",
type: "GET",
dataType: "json",
data: {
},
success: function(result) {
let features = result["features"];
let countryFeature = findFeatureFromName(countryName);
let countryCode = JSON.stringify(countryFeature.properties.iso_a2).replace(/"/g, "")
$.ajax({
url: "assets/php/countryInformation.php",
type: 'POST',
dataType: 'json',
data: {
country: countryCode
},
success: function(result) {
console.log(result);
console.log(JSON.stringify(result));
let capitalCity = (result['data'][0]['capital']);
console.log(capitalCity)
fetch(`https://api.openweathermap.org/data/2.5/weather?q=${capitalCity}&APPID=2d48b1d7080d436945hbctest09ea964e645ccd1ec93f&units=metric`)
.then(response => response.json())
.then(data => {
console.log(data)
$('#wind').html(data['wind']['speed']);
$('#description').html(data['weather']['description']);
})
}
})
}
})
document.getElementById('capital').textContent = capitalCity
}
The date
ID in the HTML is correctly returned but capital
and description
are not being returned and I can't see why?