I am attempting to have an HTML page update a textarea with content from a text file every second, using JavaScript's setInterval function. However, the function inside the setInterval call only seems to run once.
Javascript:
// Send a GET request to the given location
function sendRequest(location, nonblocking) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", location, nonblocking);
xmlhttp.send();
return xmlhttp.responseText;
}
// Refresh the communication log
function refreshLog() {
document.getElementById("comm_log").value = sendRequest("src/log.txt", false);
}
window.setInterval(refreshLog, 1000);
The request is not asynchronous simply because the text file will never be long, and this is something I am trying to throw together quickly.
HTML:
<html>
<head>
<style type="text/css">
textarea {
width: 98%;
height: 80%;
resize: none;
font-family: "Courier New";
}
</style>
<script type="text/javascript" src="src/script.js"></script>
</head>
...
<textarea id="comm_log" readonly></textarea>
...
</html>
Anyone have ideas?