根据收到的响应,在Ajax成功后重定向

时间:2014-03-16 16:26:36

标签: ajax

success: function(res) {
                            var obj = jQuery.parseJSON(res);
                            var loginResponse = obj.Result.success;
                            alert(loginResponse);
                            if(loginResponse = "true")
                            {
                                location.href = "http://www.google.com/"
                            }
                            else
                                alert("Login Failed");
                        }
                    });

我的资源如下:

{"Result":{"success":true,"userId":"ssressWRTc","dateOfFirstLogin":"2014-03-15 05:24:40"}}

但它总是警告"登录失败"即使成功是真的。

1 个答案:

答案 0 :(得分:0)

var obj = {
    "Result": {
        "success": true,
            "userId": "ssressWRTc",
            "dateOfFirstLogin": "2014-03-15 05:24:40"
    }
};


var loginResponse = obj.Result.success;
alert(loginResponse);
if (loginResponse === true) {
    window.location.href = 'http://www.google.com';
} else alert("Login Failed");