function sendMessage() { let id = window.location.href.split("/").slice(-1)[0] message = document.getElementById("chatbox-input-box").value document.getElementById("chatbox-input-box").value = '' let chatbox = document.getElementById("chatbox"); chatbox.innerHTML += `
${message}
`; chatbox.scrollTop = chatbox.scrollHeight; var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4) { if (this.status == 200) { message = this.responseText.replace("\n", "
"); } else { message = "Encountered an error while trying to get a response."; } chatbox.innerHTML += `
${this.responseText}
`; chatbox.scrollTop = chatbox.scrollHeight; } }; xhttp.open("GET", `/bot/chat/${id}/message`, true); xhttp.send(); return false; }