document.getElementById("send").addEventListener("submit", async e => { e.preventDefault(); const form = e.target; const data = new FormData(form); fetch("/api/messages", { method: 'POST', body: JSON.stringify({ threadID: data.get("threadID"), content: data.get("content") }), headers: { "Content-Type": "application/json" } }).then(res => res.json()) .then(res => { if (res.result.error) return alert(res.result.error); form.reset(); const message = res.result; document.getElementById("messages").innerHTML += `

${new Date(message.time).toLocaleString()}

${message.author.name} ${message.author.name}:

${message.content}


0

`; }).catch(err => { alert(err); }); });