我正在使用 Ajax 来提交这个。所有以box结尾的变量都是全局的。
不是完整的代码,请放心 init 等其他部分正在工作。
function begin() {
if (confirm("Are you sure you want to proceed. This is completely up to you and all consequences go towards you!!"))
{
var usernameName = usernameBox.getAttribute("name");
var passwordName = passwordBox.getAttribute("name");
var hiddenName = hiddenBox.getAttribute("name");
var username = usernameBox.value;
var password = passwordBox.value;
var hidden = hiddenBox.value;
if (username !== "" && password !== "")
{
var http = new XMLHttpRequest();
http.open("POST", "<?php echo $url_base, $action?>");
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.onreadystatechange = function()
{
console.log(http.readyState + " " + http.status);
if (http.readyState == 4 && http.status == 200)
{
alert(http.responseText);
}
else
{
alert("We had an error!!!");
}
}
var query = hiddenName + "=" + hidden + "&" + usernameName + "=" + username + "&" + passwordName + "=" + password;
//var query = usernameName + "=" + username + "&" + passwordName + "=" + password;
console.log(query);
http.send(query);
}
else
{
alert("don't be a fool fill out the info");
}
}
else
{
alert("No refunds!!");
}
}
表格如下。当我使用提交而不是onclick
然后使用 Ajax 时,此表单完美地工作,任何特定的原因。它可能是表单名称。如果您想知道,我无权访问服务器。
<form name="signin_form" action="<?php echo $url_base,$action?>" method="post"> <input id='hidden' type="hidden" name="loginPage" value="student"> <label>Username <input id='userid' size="25" name="student_userid" tabindex="0"><br/></label> <label> Password<input id='password' type="password" size="25" name="student_password"></br></label> <input id='submit' style="COLOR: #6373b5" type="button" value="Sign In" width="100px" onclick="begin();"> </form>