Add assets/js/login.js
login page with api
This commit is contained in:
parent
ea92027a3c
commit
fe065f3390
44
assets/js/login.js
Normal file
44
assets/js/login.js
Normal file
@ -0,0 +1,44 @@
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
let nickname, password;
|
||||
|
||||
function handleSubmit(event) {
|
||||
event.preventDefault();
|
||||
|
||||
nickname = document.getElementById('nickname').value;
|
||||
password = document.getElementById('password').value;
|
||||
|
||||
pageStatusUpdate();
|
||||
}
|
||||
|
||||
function pageStatusUpdate() {
|
||||
const req = {
|
||||
nickname,
|
||||
password
|
||||
};
|
||||
|
||||
|
||||
const apiUrl = 'http://127.0.0.1:1025/login';
|
||||
fetch(apiUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(req)
|
||||
})
|
||||
.then(response => {
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
}
|
||||
})
|
||||
.then(data => {
|
||||
if (data && data.status === 0) {
|
||||
window.location.href = '/list-rooms';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const form = document.querySelector('form');
|
||||
form.addEventListener('submit', handleSubmit);
|
||||
|
||||
setInterval(pageStatusUpdate, 1000);
|
||||
});
|
Loading…
Reference in New Issue
Block a user