-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathlogin.js
More file actions
27 lines (25 loc) · 789 Bytes
/
login.js
File metadata and controls
27 lines (25 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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.open("POST", "php/login.php", true);
xhr.onload = ()=>{
if(xhr.readyState === XMLHttpRequest.DONE){
if(xhr.status === 200){
let data = xhr.response;
if(data === "success"){
location.href = "users.php";
}else{
errorText.style.display = "block";
errorText.textContent = data;
}
}
}
}
let formData = new FormData(form);
xhr.send(formData);
}