我有此表单来填写电子邮件地址并提交按钮,如果服务器成功处理了电子邮件地址,则应显示成功组件,如果没有成功,则应显示错误组件,现在提交时,Chrome和IE11都将发送从服务器到电子邮件地址的电子邮件成功,但是只有chrome显示成功消息,而IE11首先显示错误消息,然后显示成功消息。我想知道是什么问题?
Form.addEventListener('submit', function(e) {
e.preventDefault();
handleSubmit();
});
function handleSubmit() {
var url = 'https://serveURLXXXXX';
var xhr = new XMLHttpRequest();
xhr.open('POST', url, true);
xhr.responseType = 'json';
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onerror = function () {
console.log('** An error occurred while sending email address.');
};
xhr.onreadystatechange = function (oEvent) {
if (xhr.readyState === 4 && xhr.status === 200) {
emailSuccess.style.display = 'block'; //(here an component will show:
you email has been sent, successfully)
} else {
emailError.style.display = 'block'; //(there is someting wrong with
the email sending).
}
};
xhr.send(
JSON.stringify({email: emailAddressInput.value})
);
}