-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
33 lines (29 loc) · 1.16 KB
/
script.js
File metadata and controls
33 lines (29 loc) · 1.16 KB
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
document.getElementById('loginForm').addEventListener('submit', async function(e) {
e.preventDefault();
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
const messageDiv = document.getElementById('message');
try {
const response = await fetch('http://localhost:5000/api/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ username, password })
});
const data = await response.json();
if (data.success) {
messageDiv.textContent = data.message;
messageDiv.className = 'success';
setTimeout(() => {
alert('Welcome ' + username + '! In a real application, you would be redirected to a dashboard.');
}, 500);
} else {
messageDiv.textContent = data.message;
messageDiv.className = 'error';
}
} catch (error) {
messageDiv.textContent = 'Error connecting to server';
messageDiv.className = 'error';
}
});