[英]javascript any type of Redirection not working
我有一個簡單的JavaScript,可以檢查用戶是否輸入了正確的用戶名和密碼,並將其重定向到管理頁面,但是它不起作用。 這是我的代碼:
$(document).ready(function(){
$('#login').click(function(){
var username = $('#user').val();
var password = $('#pass').val();
if(username == "")
{
$('#dis').slideDown().html("<span>Please type username</span>");
return false;
}
if(password == "")
{
$('#dis').slideDown().html("<span id='error'>Please type password</span>");
return false;
}
if(username == "admin" && password == "admin")
{
window.location("registrar.html");
}
else
{
alert("Incorrect Username or Password");
}
});
});
我已經嘗試了不同的方法,但仍然無法正常工作。.我也嘗試將頁面的完整地址放在http://localhost/folder/registrar.html,但也無法正常工作...
更換:
window.location("registrar.html");
帶有:
window.location.href = "registrar.html";
這是我出來的解決方案。 我添加這個PHP
session_start();
$error = $user = $pass = "";
$check = "";
if(!empty($_GET['user']) && !empty($_GET['pass']))
{
$user = htmlentities($_GET['user']);
$pass = htmlentities($_GET['pass']);
if($user == "admin" && $pass == "admin")
{
$_SESSION['user'] = $user;
$_SESSION['pass'] = $pass;
header("Location: registrar.html");
}
else
{
echo "<script>alert('Incorrect Username or Password');
window.location.href = 'login.html';</script>";
}
}
並將以下代碼刪除到javascript中:
if(username == "admin" && password == "admin")
{
window.location = "registrar.html";
}
else
{
alert("Incorrect Username or Password");
}
// same as an HTTP redirect
window.location.replace("registrar.html");
// same as clicking on a link
window.location.href = "registrar.html";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.