login.js
980 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
28
29
30
31
32
33
34
35
36
37
38
39
40
function login() {
message("Espere...");
const usr = document.getElementsByName("usuario")[0];
const psw = document.getElementsByName("contrasena")[0];
function BadInputException(input) {
this.error = "badinput";
this.input = input;
}
if (usr.checkValidity() === false) {
usr.reportValidity("Por favor llene este campo");
throw BadInputException(input);
}
if (psw.checkValidity() === false) {
psw.reportValidity("Por favor llene este campo");
throw BadInputException(input);
}
const obj = {
"url": "/login",
"contentType": "application/json",
"async": true,
"data": { "usuario" : usr.value, "contrasena" : psw.value },
"success": (response) => {
console.log(response)
if (response === "true")
location.href = "/";
else
message(response);
},
"error": (response) => message(response),
"timeout": 120000,
"ontimeout": (response) => message("La conexión tardó demasiado.")
}
const ajax = new Ajax(obj);
ajax.post();
}