ajax 函数的成功部分永远不会达到。我已经花了几个小时,仍然没有成功。代码已经被剥夺了几乎所有必要的东西,只是为了尝试消除任何可能的问题,但它仍然不起作用。
下面是我试图开始工作的剥离代码。谢谢你的帮助。
阿贾克斯:
function validLogin(){
var url = "loginProcessAjax.php";
$.ajax({
type: 'POST',
url: url,
beforeSend: function() {
//
alert("sdfs");
},
success: function(html) {
alert("success");
alert(html.getElementsByTagName("worked")[0].firstChild.nodeValue);
},
error: function( error ) {
console.log(error);
}
});
}
PHP:
<?php
header("Content-type: text/xml");
echo "<?xml version='1.0' encoding='ISO-8859-1'?>";
echo "<worked>";
echo "success";
echo "</worked>";
?>
HTML:
<form method="post" action="" id="ourLoginFormID_JS">
<div class="ourContactFormElement2">
<label for="username">Username:</label>
<input type="text" id="username" name="username" autocomplete="off" class="required" value="<?php if(isset($_POST['username'])) echo htmlentities($_POST['username']); ?>" />
</div>
<div class="ourContactFormElement2">
<label for="password">Password:</label>
<input type="password" id="password" name="password" autocomplete="off" class="required"/>
</div>
<div class="ourContactFormElement2">
<label> </label>
<input type="submit" name="loginButton" id="loginButton" value="Login!" onclick="validLogin()"/>
</div>
<div id="statusLogin"></div>
</form>
在 beforeSend 中,不会生成带有 xml 的警报框。另一个这样做,所以我知道它至少在调用该函数。