0
我有一個登錄頁面。當用戶輸入用戶名和密碼,然後單擊登錄按鈕時,該按鈕將調用一個Ajax XmlHttpRequest,它將用戶名和密碼發送到process.php。 php處理數據,並在用戶名或密碼不正確時返回。但是,如果正確,我想將用戶重定向到session.php。 Php頭文件不起作用,因爲它需要頁面代碼,並且JavaScript不起作用,因爲它不運行代碼。我該怎麼做?PHP將用戶的另一個頁面重定向到下載的Ajax XmlHttpRequest中
這裏是阿賈克斯:
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