New to coding and seeking guidance:
I have a basic AJAX feature in my project that triggers a GET API request every 3 seconds:
<script>
$(document).ready(
function() {
setInterval(function() {
$.get('/value_one', function(res) {
$('#value_one').text(res);
});
$.get('/value_two', function(res) {
$('#value_two').text(res);
});
}, 3000);
}
);
</script>
Currently, this setup is functioning correctly. It successfully fetches data from my NodeJS server code every three seconds after the page has finished loading. However, I am looking to enhance it so that the values are also fetched upon page load, and then continue to update every three seconds thereafter. Can anyone advise on how to achieve this?