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 を含むアラート ボックスが生成されません。もう1つはそうしているので、少なくとも関数を呼び出していることがわかります。