Add login submission from front-end
This commit is contained in:
@@ -22,24 +22,42 @@
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header>
|
||||
<h1>Welcome!</h1>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<input placeholder="Username">
|
||||
<input id="username-field" placeholder="Username">
|
||||
<br>
|
||||
<input placeholder="Password">
|
||||
<input id="password-field" placeholder="Password">
|
||||
<br>
|
||||
<button>Connect</button>
|
||||
<button id="connect-button">Connect</button>
|
||||
</main>
|
||||
|
||||
|
||||
<footer>
|
||||
</footer>
|
||||
|
||||
<script>
|
||||
|
||||
let btn = document.getElementById("connect-button");
|
||||
btn.addEventListener("click", () => {
|
||||
let username = document.getElementById("username-field").value;
|
||||
let pwd = document.getElementById("password-field").value;
|
||||
|
||||
let data = {
|
||||
username: username,
|
||||
password: pwd
|
||||
};
|
||||
|
||||
fetch("/login", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(data)
|
||||
})
|
||||
.then(response => response.text())
|
||||
.then(result => {
|
||||
console.log("Server response:", result);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error("Error:", error);
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user