I've tried many solutions posted online but no one can solve my problem. I have a php page with some basic element. In particular I want to realize a text area (read only) that display the text of a txt file. I want it to "auto update" the text every 1 second or less without pressing any button or reloading the page...this is what I have now:
<html>
<head>
<title>Yun_TempServer_Home</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
function getFileContents() {
var client = new XMLHttpRequest();
client.open('GET', '/sd/status.txt');
client.onreadystatechange = function () {
document.querySelector("textarea").value = client.responseText;
}
client.send();
}
setInterval(getFileContents, 1000);
</script>
</head>
<body>
<textarea id="textarea"rows="15" cols="50" readonly>
</textarea>
</body>
</html>
For now it works but sometimes it reads only one part of the new text, other times it will not update the code for 30-40 seconds. I'm at a very basic level for both php, html and javascript, so please explain well how can I solve this..
Thanks