<!DOCTYPE html> <html> <body> <h1>Status</h1> <p id="minecraft_status" style="display:inline"></p> <button type="btnStart" onclick="sendStatusChange(true)">Start</button> <button type="btnStop" onclick="sendStatusChange(false)">Stop</button> <h1>Logs</h1> <pre id="minecraft_log"> </pre> </body> </html> <script> function sendStatusChange(status) { var http = new XMLHttpRequest(); var url = "/minecraft-status"; var data = JSON.stringify( { status: status} ) http.open("POST", url, true); //Send the proper header information along with the request http.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); // send the collected data as JSON http.send(data); } function refreshStatus() { fetch("/minecraft-status") .then(res => res.json()) .then((out) => { document.getElementById('minecraft_status').innerText = "has started: " + out.status; }) .catch(err => { throw err }); setTimeout(refreshStatus, 5000); } function refreshLog() { fetch("/minecraft-log") .then(res => res.json()) .then((out) => { document.getElementById('minecraft_log').innerText = out.log; }) .catch(err => { throw err }); setTimeout(refreshLog, 5000); } setTimeout(refreshStatus, 500); setTimeout(refreshLog, 500); </script>