const form = document.querySelector(".login form"),
continueBtn = form.querySelector(".button input"),
errorText = form.querySelector(".error-text");

form.onsubmit = (e)=>{
    e.preventDefault();
}

continueBtn.onclick = ()=>{
    let xhr = new XMLHttpRequest();
    xhr.responseType = 'json';
    xhr.open("POST", "php/login.php", true);
    xhr.onload = ()=>{
      if(xhr.readyState === XMLHttpRequest.DONE){
          if(xhr.status === 200){
            var jsonResponse = xhr.response;
              if(jsonResponse.status === "success" && jsonResponse.user_id != ''){
                location.href = "chat.php?user_id="+jsonResponse.user_id;
              }else{
                location.href = "users.php";
              }
          }
      }
    }
    let formData = new FormData(form);
    xhr.send(formData);
}