我想防止根据 AJAX 响应提交主表单。
HTML是这样的...
<form action="test.php" method="POST">
<input type="text" name="email" id="email" onblur="ajax_check_email();">
<span id="email_alert"></span>
<input type="submit" name="submit">
</form>
现在我有一个带有ajax查询的js文件-
function ajax_email_check () {
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("email_alert").innerHTML=xmlhttp.responseText;
}
}
var email = document.getElementById("email").value;
xmlhttp.open("GET","ajax/check_email.php?email=" + email,true);
xmlhttp.send();
}
现在 php 页面返回Email Already Exists
或Success
.
一切顺利,但在显示“电子邮件已经存在......!”的文本之后 当我点击提交时,主表单正在提交。它应该阻止我。但是我要怎么做呢?