const form = document.getElementById('loginForm') form.addEventListener('submit', (event) => { event.preventDefault() const email = document.getElementById('email').value const password = document.getElementById('password').value fetch('/login_user', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username: email, password: password }) }) //expect index.html redirect and navigate to index.html .then(response => { if (response.redirected) { window.location.href = response.url } else { console.log(response) } }) })