For a web app, i am trying to fetch data from internal API and show it changing every second or so on the homepage. The internal PHP sets two variables, which are read by folowwing javascript code :
$(window).load(function() {
setInterval(function() {
var stats = "";
stats += "<span class='styleForStats'>";
stats += stat1;
stats += "</span>";
$('#myBox').html(stats);
}, 1000);
});
Now, the problem with this is, i set the variable stat1 through PHP, and that is done on load time of the page. So it won't get the latest value from PHP code.
Can i somehow, make a call to internal PHP file from JS everytime within the setInterval function so as to get live values every time. I thought of AJAX calls, but wouldnt they be only for external APIs ?