我试图在 Ajax 脚本中成功登录后刷新页面,但页面未刷新。我被迫手动刷新页面,然后才会显示已登录。在此先感谢您的帮助,非常感谢。
这是ajax的登录脚本;
$("document").ready(function() {
$("#what").click(function() {
var email = $("#emailLogin").val();
var password = $("#passwordLogin").val();
var dataString = 'email='+email+'&password='+password;
$.ajax({
type: "POST",
url: "authenticate.php",
data: dataString,
success: function(response){
//alert (response);
if (response == 0) {
$("#problem").html("Please enter correct details");
} else {
window.location = "index.php";
}
}
});
return false;
});
});
这是用于验证表单的 php 脚本
// authenticate.php
session_start();
require_once "database.php";
db_connect();
require_once "auth.php";
$user_id = credentials_valid($_POST['email'], $_POST['password']);
if($user_id){
log_in($user_id);
if($_SESSION['redirect_to']){
header("Location: " . $_SESSION['redirect_to']);
unset($_SESSION['redirect_to']);
}else{
header("Location: index.php");
}
}else{
echo "0";
}
?>