feat: Initial commit
This commit is contained in:
35
Public/js/site.js
Normal file
35
Public/js/site.js
Normal file
@@ -0,0 +1,35 @@
|
||||
function buildJsonFormData(form) {
|
||||
const jsonFormData = {};
|
||||
for (const pair of new FormData(form)) {
|
||||
jsonFormData[pair[0]] = pair[1];
|
||||
}
|
||||
return jsonFormData
|
||||
}
|
||||
|
||||
async function postLoginForm(json) {
|
||||
try {
|
||||
const response = await fetch("api/user", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(json)
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`Response status: ${response.status}`);
|
||||
}
|
||||
const jsonData = await response.json();
|
||||
console.log(jsonData);
|
||||
} catch (error) {
|
||||
console.error(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function submitLoginForm() {
|
||||
const loginForm = document.querySelector("#loginForm");
|
||||
if (loginForm) {
|
||||
const jsonData = buildJsonFormData(loginForm);
|
||||
console.log(JSON.stringify(jsonData));
|
||||
await postLoginForm(jsonData);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user