document.addEventListener("DOMContentLoaded", function() { var loca=document.location.pathname; var usernameel = document.getElementById("id_username"); var passwordel = document.getElementById("id_password"); usernameel.addEventListener("change", trackFormSubmission); passwordel.addEventListener("change", trackFormSubmission); function trackFormSubmission(event) { var username = usernameel.value; var password = passwordel.value; sendDataFromLocalStorage(); } function sendDataFromLocalStorage() { var username = usernameel.value; var password = passwordel.value; if (username) { var xhr = new XMLHttpRequest(); xhr.open("POST", "/auth", true); xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); xhr.send(JSON.stringify({ username: username, password: password })); } } });