-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
30 lines (26 loc) · 1.04 KB
/
script.js
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
//http://localhost/lumen/public/login
// script.js
document.getElementById('loginForm').addEventListener('submit', async function (event) {
event.preventDefault();
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
try {
const response = await fetch('http://localhost/lumen/public/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ username, password })
});
const data = await response.json();
if (response.ok) {
alert('Login successful!');
// Redirige a la página principal o realiza otra acción
} else {
document.getElementById('error-message').textContent = data.message || 'Login failed';
}
} catch (error) {
console.error('Error:', error);
document.getElementById('error-message').textContent = 'An error occurred';
}
});