ds342222222 2017-02-10 11:27
浏览 26

检查db然后使用Ajax重定向

So it's my first time handling or rather using ajax and it still rattles my mind. I made this ajax function so when everytime I push a button it checks the value of something on db and if it's true then it should redirect. It works fine or rather redirect when I refresh the webpage but that isn't what I was expecting, I was expecting that if the value on the db being checked is "EQUAL TO" or True then it should redirect without me having to refresh the page just so it can do it's stuff. Hoping for some insights, thanks!

My home.php has this:

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

My 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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 BP神经网络控制倒立摆
    • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
    • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
    • ¥30 Unity接入微信SDK 无法开启摄像头
    • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
    • ¥20 cad图纸,chx-3六轴码垛机器人
    • ¥15 移动摄像头专网需要解vlan
    • ¥20 access多表提取相同字段数据并合并
    • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
    • ¥20 Java-Oj-桌布的计算