0
I’m building a page that has a carousel (with bootstrap 4) that displays some information about temperatures. This information comes from a XML that will be updated whenever any change occurs.
I’m doing the tests by changing the file XML manually, but I can’t see the changes. I’ve tried setTimeout
and the setInterval
(the setInterval
repeats the whole block HTML) and not being able to visualize the changes, it seems that in the case of setTimeout
, he does not carry the XML again.
Could someone help me unravel this mystery? I thank you in advance for your attention :)
Code:
function temperatures() {
'use strict';
$.get('temperature.xml', function (data) {
$(data).find('temperature').each(function () {
let $temperature = $(this);
let type = $temperature.find('type').text();
let value = $temperature.find('value').text();
let temperatures = '<div class="carousel-item temperature">';
temperatures += '<span class="sensor-value">' + value + '</span>';
temperatures += '<span class="sensor-title">' + type + '</span>';
temperatures += '</div>';
$('.temperatures').append($(temperatures));
});
});
setTimeout(temperatures, 1000);
}
$(function () {
temperatures();
});
setTimeout
is a "pause", it only runs once. Already thesetInterval
, it creates an interval that will repeat itself endlessly. Make sure it is not a problem with "cache".– Valdeir Psr