mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 19:20:55 +00:00
disable the subscribe button while waiting for subscription
This commit is contained in:
parent
4303c91b28
commit
0675ff5515
@ -30,31 +30,33 @@ You can unsubscribe at any time.
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function submitForm() {
|
async function submitForm() {
|
||||||
|
|
||||||
const emailInput = document.getElementById("email");
|
const emailInput = document.getElementById("email");
|
||||||
const successMessage = 'Thank you for your registration. Please check your email to confirm.';
|
const successMessage = 'Thank you for your registration. Please check your email to confirm.';
|
||||||
const url = 'https://mail.jspsych.org/?p=asubscribe&id=6';
|
const url = 'https://mail.jspsych.org/?p=asubscribe&id=6';
|
||||||
const resultDiv = document.getElementById("result");
|
const resultDiv = document.getElementById("result");
|
||||||
|
const subscribeButton = document.querySelector('button#subscribe');
|
||||||
|
|
||||||
fetch(url, {
|
// Disable the subscribe button
|
||||||
method: 'POST',
|
subscribeButton.disabled = true;
|
||||||
headers: {
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(url, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded', // Adjust based on your content type
|
'Content-Type': 'application/x-www-form-urlencoded', // Adjust based on your content type
|
||||||
},
|
},
|
||||||
body: new URLSearchParams(new FormData(document.getElementById('subscribeform'))),
|
body: new URLSearchParams(new FormData(document.getElementById('subscribeform'))),
|
||||||
})
|
});
|
||||||
.then(async response => {
|
|
||||||
const r = await response.text();
|
const data = await response.text();
|
||||||
console.log(r);
|
|
||||||
})
|
|
||||||
.then(data => {
|
|
||||||
console.log(data)
|
|
||||||
resultDiv.innerHTML = successMessage;
|
resultDiv.innerHTML = successMessage;
|
||||||
})
|
} catch (error) {
|
||||||
.catch(error => {
|
|
||||||
resultDiv.innerHTML = 'An error occurred. Please try again later.';
|
resultDiv.innerHTML = 'An error occurred. Please try again later.';
|
||||||
});
|
} finally {
|
||||||
|
// Re-enable the subscribe button
|
||||||
|
subscribeButton.disabled = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
document.querySelector('button#subscribe').addEventListener('click', submitForm);
|
document.querySelector('button#subscribe').addEventListener('click', submitForm);
|
||||||
|
Loading…
Reference in New Issue
Block a user