I created a python API which returns based on the input one of three outputs: "Success (email already exists)" "Success" "Invalid Email"
I have atatched what the output looks like when called directly from a browser. So the issue is when I call this API in my code, it doesnt execute switching to another page and keeps showing a error message I created if the API returns "Invalid Email". It shows the error message and doesnt execute even if the API returns "Success". I know the API is working and returning the correct outputs as the API is executing the relative commands on some files. How can I fix this? Here is a snippet from my websites code.
form.addEventListener('submit', (event) => {
event.preventDefault();
const formData = new FormData(form);
const name = formData.get('name');
const email = formData.get('email');
const apiURL = `http://censored-for-privacy/?name=${name}&email=${email}`;
fetch(apiURL)
.then(response => response.text())
.then(data => {
if (data === 'Success (email already exists)' || data === 'Success') {
window.location.href = 'main.html';
} else if (data === 'Invalid Email') {
errorMessage.style.display = 'block';
form.reset();
}
})
.catch(error => {
console.error('Error:', error);
errorMessage.style.display = 'block';
form.reset();
});
});
I have tested the API and it works well, I tried changing 'main.html' to a url for google still doesnt work. It executes the alternate function. Found a fix....