document.getElementById('login_form').onsubmit = function(e) { e.preventDefault(); const user = document.getElementById('l_fld').value; const pass = document.getElementById('p_fld').value; // Encode credentials to Base64 const authHeader = 'Basic ' + btoa(user + ':' + pass); fetch('/private/index.html', { method: 'GET', headers: { 'Authorization': authHeader } }) .then(response => { if (response.ok) { window.location.href = '/private/'; // Redirect on success } else { alert('Invalid credentials'); // Handle error } }); };