document.addEventListener('DOMContentLoaded', function() { let nickname, password; function handleSubmit(event) { event.preventDefault(); nickname = document.getElementById('nickname').value; password = document.getElementById('password').value; pageStatusUpdate(); } function pageStatusUpdate() { const req = { nickname, password }; const apiUrl = 'http://127.0.0.1:1025/login'; fetch(apiUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(req) }) .then(response => { if (response.ok) { return response.json(); } }) .then(data => { if (data && data.status === 0) { window.location.href = '/list-rooms'; } }); } const form = document.querySelector('form'); form.addEventListener('submit', handleSubmit); setInterval(pageStatusUpdate, 1000); });