-1

我正在使用 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);
4

5 回答 5

1

尝试

document.location = url;.

或者

document.location.href = url;

于 2013-01-07T07:29:39.333 回答
1

改变

$(location).attr('href',url);

location = url
于 2013-01-07T07:35:01.820 回答
0

你可以试试

if(data==1) { window.location = "页面网址"; }

或者

if(data==1) {window.location.href = "页面网址"; }

还要检查 if 循环是否满足

于 2013-01-07T08:05:02.097 回答
0
// similar behavior as an HTTP redirect
window.location.replace("http://localhost/shop/admin/index.php");

// similar behavior as clicking on a link
window.location.href = "http://localhost/shop/admin/index.php";
于 2013-01-07T07:31:25.280 回答
0

你可以简单地使用window.location = "http://localhost/shop/admin/index.php";

于 2013-01-07T07:30:10.873 回答