我花了最后一个小时左右在这里和谷歌搜索,但没有成功。我有一个表格,我想通过 POST 提交。javascript 运行并验证良好,它甚至“提交”表单。但是当它这样做时,它只是重新加载页面。不发送 POST 标头(在 Firefox 中使用 Firebug 确认)。就好像它只是重新加载页面而不是提交它。
此表单嵌入在 addUser.php 页面中。
<form action="addUser.php" method="post" name="NewUser">
<div data-role="field-contain">
<label label-for="EmpID" class="ui-hidden-accessible">Enter Employee ID</label>
<input name="EmpID" id="EmpID" placeholder="Employee ID" value="" autocomplete="off" title="Enter Employee ID" type="number" required autofocus>
<label label-for="UserName" class="ui-hidden-accessible">Enter username</label>
<input name="UserName" id="UserName" placeholder="Username" value="" autocomplete="off" title="Enter the new username" required>
<p>
<label label-for="NewPass1" class="ui-hidden-accessible">Enter Your Current Password</label>
<input name="NewPass1" id="NewPass1" placeholder="New Password" value="" type="password" autocomplete="off" title="Must be at least 8 characters, with numbers and upper and lower case letters." required>
</p>
<p>
<label label-for="NewPass2" class="ui-hidden-accessible">Enter Your Current Password</label>
<input name="NewPass2" id="NewPass2" placeholder="Verify Password" value="" type="password" autocomplete="off" title="Re-enter your chosen new password." required>
</p>
</div>
<button type="button" name="submitButton" value="submitButton" data-theme="d" data-inline="true" data-icon="check" data-iconpos="left" onclick="validateForm ()">
Add User
</button>
这是Javascript:
function validateForm()
{
var reason = "";
reason += validateEmpID();
reason += validateUserName();
reason += validateNewPassword();
if (reason != "") {
alert("There are some errors with the data you entered:\n" + reason);
return false;
} else {
document.NewUser.submit();
}
}
我尝试了各种不同的调用提交方法,结果都一样。非常感谢任何帮助。
谢谢加雷斯