document.querySelector("#login").onsubmit = async (event) => { event.preventDefault(); const form = new FormData(event.target); const body = JSON.stringify({ username: form.get("username"), password: form.get("password"), }); const res = await fetch("/api/login", { method: "POST", headers: new Headers({ "Content-Type": "application/json" }), body, }).then((res) => res.json()); console.log(res); };