我忘记通过表单在提交时没有调用我的 javascript ajax,这是我的代码
<form onsubmit="SendMail(this.email.value);">
<input type="email" name="email" placeholder="E-Mail" required>
<input type="submit" id="black_button" value="Request Password Renewal Code">
</form>
这是我的 JS 脚本
<script>
function SendMail(email)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var response = xmlhttp.responseText;
if(response=='redirect')
{
document.location.href="forgotpassword.php?success=1"; //If the response is redirect then redirect the user to another page
}
else
{
$("#FPErrorMSG").html(xmlhttp.responseText);
$("#FPErrorMSG").css("display","block"); // If not then show the error message
}
}
}
xmlhttp.open("GET","system/forgotpassword/sendmail.php?email=" + email,true);
xmlhttp.send();
}
</script>
它不调用 Javascript 函数,例如当我输入我的电子邮件为 abc@d.com 时,它只会将我的 url 更改为 forgotpassword.php?email=abc@d.com。当我将输入字段名称从电子邮件更改为邮件时,它会将我的网址更改为 forgotpassword.php?mail=abc@d.com