diff --git a/static/build/index.js b/static/build/index.js index 6467823..a265cc9 100644 --- a/static/build/index.js +++ b/static/build/index.js @@ -68,7 +68,6 @@ function checkUsernameAvailability() { xhr.send(); } - function submitSignup() { // Disable the button to prevent multiple clicks submitBtn.disabled = true; @@ -93,23 +92,24 @@ function submitSignup() { formData.append("password", password); // Send the signup request as form data - fetch("/signup", { - method: "POST", - body: formData - }) - .then(response => { - if (response.ok) { - return response.json(); - } else { - throw new Error("Signup request failed"); + const xhr = new XMLHttpRequest(); + xhr.open("POST", "/signup", true); + + xhr.onreadystatechange = function () { + if (xhr.readyState === 4) { + if (xhr.status === 200) { + // Signup successful + console.log("Signup successful"); + window.location.href = "/welcome"; // Redirect to success page + } else { + // Signup failed, display the error message + const response = JSON.parse(xhr.responseText); + console.error("Signup failed:", response.error); + } } - }) - .then(() => { - window.location.href = "/welcome"; - }) - .catch(error => { - console.error(error); - }); + }; + + xhr.send(formData); // Enable the button and remove the spinner after 5 seconds setTimeout(function () { @@ -121,6 +121,7 @@ function submitSignup() { + function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); }