After sending a POST request to the local json-server-auth database, there is an issue with the page reloading. Is there a way to prevent this from happening? I am concerned about losing data due to the page refresh.
<form class="form">
<input type="email">
<input type="password">
<button>Register</button>
</form>
<code lang="javascript">
const form = document.querySelector('.form')
form.addEventListener('submit', async (e) => {
e.preventDefault()
let data = {
email: e.target[0].value,
password: e.target[1].value
}
let res = await fetch('http://localhost:8080/signup', {
method: "POST",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
let json = await res.json()
console.log(json)
return false
})
I tested the code in Codepen and didn't experience any page reloads, but when using Live Server in VS Code, the page refreshes upon sending the request from the browser.