我正在使用 jquery 进行登录,它工作正常,但如果成功 ==1,我必须在 index.php 页面上重定向登录页面,否则它将显示错误。但它不会在索引页面上重定向并保持在同一登录页面上。任何人都可以帮助我。这是我的代码
<script src="http://code.jquery.com/jquery-1.7.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#form_login').submit(function() {
var uname= $('#username').val(); alert(uname);
var password=$('#password').val(); alert(password);
$.ajax({
type: "POST",
url: "http://localhost/shop/admin/match_login.php",
data: {uname: uname, password:password},
success:function(data){
if(data==1){ alert("right");
var url='http://localhost/shop/admin/index.php';
$(location).attr('href',url);
}else{ alert("wrong");
$('#login-msg').html("Wrong User Name/Password");
}
} //call function after success
});
return false;
});
});
</script>
session_start();
require_once("../utils/config.php");
require_once("../utils/functions.php");
require_once("../utils/dbClass.php");
require_once("../utils/database.php");
$objNEWDB = new NEWMySQL;
$host= $_SERVER['HTTP_HOST'];
$url=$_SERVER['SCRIPT_URI'];
$hostnew=substr($url,0,-16);
$user_name= $_POST['uname'];
$password= $_POST['password'];
$SQL = "Select * from admin where UserName ='".$user_name."' and Password='".$password."'";
$rsUser = $objNEWDB->select($SQL); //print_r($rsUser);
//$res=mysql_fetch_array($rsUser);
if(sizeof($rsUser)==1 && $rsUser[0]['Status']=='1')
{
$_SESSION["session_admID"] = $rsUser[0]['AdminID'];
}
echo $size= sizeof($rsUser);