将php中的json数组返回到jquery

将php中的json数组返回到jquery,php,jquery,html,json,Php,Jquery,Html,Json,我试图在php中将一个Json数组返回给jquery,但一直收到未定义的结果。 Im使用jquery模式加载登录屏幕,然后用户登录,如果登录成功,我希望他们重定向,如果不显示该操作。我使用的代码是 show: function (dialog) { $('#loginForm').on('submit', function (e) { e.preventDefault(); $('input[type=submit]', this).attr('disab

我试图在php中将一个Json数组返回给jquery,但一直收到未定义的结果。 Im使用jquery模式加载登录屏幕,然后用户登录,如果登录成功,我希望他们重定向,如果不显示该操作。我使用的代码是

show: function (dialog) {
    $('#loginForm').on('submit', function (e) {
        e.preventDefault();
        $('input[type=submit]', this).attr('disabled', 'disabled');
        var username = $("#username").val();
        var password = $("#password").val();
        var url = "../_Scripts/login.php";
        if (!username) {
            $('input[type=submit]', this).removeAttr('disabled');
            $("#loginReply").html('<img src="../_Images/round_error.png" alt="Error" width="31" height="30" /> &nbsp; Please enter your Username.').show().fadeOut(6000);
            return false;
        } else if (!password) {
            $('input[type=submit]', this).removeAttr('disabled');
            $("#loginReply").html('<img src="../_Images/round_error.png" alt="Error" width="31" height="30" /> &nbsp; Please enter your Password.').show().fadeOut(6000);
            return false;
        } else {
            $.post(url, $('#loginForm').serialize(), function (data) {
                if (data.status == true) {
                    // window.location = data.action;
                    alert(data.status);
                } else {
                    //$("#loginReply").html(data.action).show().fadeOut(10000);
                    //$("#username").val('');
                    //$("#password").val(''); 
                    //$("#loginProcessGif").hide();
                    alert(data.status);
                }
            });
        }
    });
},
有人能帮我解释为什么我会得到未定义的变量吗


谢谢你把它整理好了。发现你可以使用

header('Content-Type: application/json');
            echo json_encode(array('status' => false, 'action' => 'Username/Password incorrect'));

要返回一个Json数组:)

您不能在if语句中只返回一个Json编码的数组,并期望它去任何地方。。。。所有这些代码都在你没有显示的函数中吗?还有吗?不,不是在函数中。我最初使用echo返回数据,但当用户正确登录并且页面刚刚加载到jquery WindowsSimilar时,我正在努力刷新页面:
header('Content-Type: application/json');
            echo json_encode(array('status' => false, 'action' => 'Username/Password incorrect'));