38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
function doAccountAction(requestData, successMessage, failureMessage) {
|
|
return fetch('/account', {
|
|
method: 'POST',
|
|
body: requestData,
|
|
})
|
|
.then(response => {
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
}
|
|
return response.json();
|
|
})
|
|
.then(data => {
|
|
handleResponse(data, successMessage, failureMessage);
|
|
return data; // Returning the response data for further processing
|
|
})
|
|
.catch((error) => {
|
|
console.error('Error:', error);
|
|
});
|
|
}
|
|
|
|
function handleResponse(data, SuccessMessage, failureMessage) {
|
|
const StatusMessageElement = document.getElementById("StatusMessage");
|
|
|
|
if (data.Status === 'Success') {
|
|
StatusMessageElement.innerText = SuccessMessage;
|
|
} else {
|
|
StatusMessageElement.innerText = failureMessage;
|
|
}
|
|
}
|
|
|
|
function logout() {
|
|
const data = new URLSearchParams();
|
|
data.append("action", "logout");
|
|
|
|
doAccountAction(data, "Logout Successful!", "Logout failed.");
|
|
}
|
|
|