检查db然后使用Ajax重定向

时间:2017-02-10 11:27:31

标签: php ajax redirect

所以这是我第一次处理或者更确切地说使用ajax,它仍然让我大吃一惊。我做了这个ajax函数所以每当我按下一个按钮时它会检查db上的某些内容的值,如果它是真的那么它应该重定向。当我刷新网页时它工作得很好或者更确切地重定向但是这不是我期望的,我期待如果被检查的数据库上的值是“EQUAL TO”或True那么它应该重定向而不必我刷新页面只是这样它可以做到这一点。希望获得一些见解,谢谢!

我的home.php有这个:

<script src="js/ajax.js"></script>

我的Ajax JS:

$.ajax
({
    url: "testjax.php",
    type: "post",
    data: $('#Button').serialize(),
    dataType:'json',
    success: function (data) 
    {
        if (data.status=='SUCCESS')
        {
            window.location="/anotherdirectory/"; 
        }
        else 
        {}
    },
    error: function (e) {
        console.log('error:'+e);
    }
});

Testjax PHP

<?php
session_start();
require_once('path/sql.php');
require_once('path/who.php');

$userID = Who::LoggedUserID(); //Found in who.php
$userData = Who::GetUserData($userID);
$userPoints = $userData['points'];

if ($userPoints==0.00)
        {
            $tent='SUCCESS';
        }
        else
        {
            $tent='ERROR';
        }

        $ary=array("status"=>$tent);

        echo json_encode($ary);
?>

0 个答案:

没有答案