0
私はログインページを持っています。ユーザーがusername、passwordを入力し、LogInボタンをクリックすると、ボタンはAjax XmlHttpRequestを呼び出し、ユーザー名とパスワードをprocess.phpに送信します。 PHPはデータを処理し、ユーザー名またはパスワードが正しくない場合に返します。しかし、正しい場合は、ユーザーをsession.phpにリダイレクトしたいと思います。 PHPコードは実行されないため、ページコードが必要なためPHPヘッダーが機能せず、JavaScriptも機能しません。どうしたらいいですか?ここでPHPは、ダウンロードしたAjax XmlHttpRequestの別のページをリダイレクトします
は、Ajaxは次のとおりです。
function logIn() {
var loader = document.getElementById('loaderParent');
var form = document.getElementById('formI');
form.style.display = "none";
loader.style.display = "block";
setTimeout(function() {
var xhttp = new XMLHttpRequest();
var username = document.getElementById('username').value;
var password = document.getElementById('password').value;
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
// console.log(4);
document.getElementById("form").innerHTML =
this.responseText;
}
};
xhttp.open("POST", "class/process.php", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send("zone=LogIn§ion=2&username="+username+"&password="+password);
}, 500);
}
コードを表示.... – Naincy
コードを見る必要がありますが、AJAX関数の成功コールバックでJavaScriptを使用してリダイレクトを実行する必要があります。 –
コードを添付しました – MGamer333