fix for http.c
This commit is contained in:
parent
162bb122fc
commit
aa09577e9f
41
src-solution/login.html
Normal file
41
src-solution/login.html
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<!-- minimal demo of expected login functionality -->
|
||||||
|
<body>
|
||||||
|
<form onsubmit="return login(this)">
|
||||||
|
Username: <input name="username" >
|
||||||
|
Password: <input name="password" >
|
||||||
|
<input type="submit"/>
|
||||||
|
</form>
|
||||||
|
<div id="result">The result of the request will appear here.</div>
|
||||||
|
<script>
|
||||||
|
const result = document.getElementById('result');
|
||||||
|
|
||||||
|
function login(form) {
|
||||||
|
fetch("/api/login",
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify({
|
||||||
|
username: form.username.value,
|
||||||
|
password: form.password.value
|
||||||
|
})
|
||||||
|
}).then((res) => {
|
||||||
|
if (res.status == 200) {
|
||||||
|
res.json().then((data) => {
|
||||||
|
result.innerText = `Success: token ${JSON.stringify(data)}`;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
result.innerText = `Received: ${res.status} ${res.statusText}`;
|
||||||
|
}
|
||||||
|
}).catch((error) => {
|
||||||
|
result.innerText = `Error: ${error.message}`;
|
||||||
|
});
|
||||||
|
|
||||||
|
return false; // prevent default action
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
Loading…
x
Reference in New Issue
Block a user