When submitting my form, It just refreshes the page and adds a question mark at the end of the URL. However, when I enter this into the console, the code runs perfectly. Any ideas?
document.querySelector('form').onsubmit = function() {
const rec = document.querySelector('#compose-recipients').value;
const sub = document.querySelector('#compose-subject').value;
const bod = document.querySelector('#compose-body').value;
fetch('/emails', {
method: 'POST',
body: JSON.stringify({
recipients: rec,
subject: sub,
body: bod
})
})
.then(response => response.json())
.then(result => {
// Print result
console.log(result);
});
load_mailbox('sent');
return false;
}