I have a dilemma with two basic web pages.
test.php:
<div id="demo"></div>
<script>
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = this.responseText;
}
};
xhttp.open("GET", "sse.php", true);
xhttp.send();
}
var myVar = setInterval("loadDoc()", 2000);
</script>
sse.php
<?php
echo time();
?>
The issue is that it runs perfectly on my personal computer. Every two seconds, sse.php is fetched and the content in the demo-div updates accordingly.
However, when I try to run the same script on my Bluehost website, it only fetches once (after two seconds) and then stops working.
An interesting observation is that when I manually refresh the sse.php page in another tab, the content in the demo div changes! I've tried troubleshooting the problem but I'm running out of ideas.
Any suggestions or insights are greatly appreciated!
Thank you.