在 json 调用后重定向

Redirecting after a json call?

本文关键字:重定向 调用 json      更新时间:2023-09-26

我的应用程序上有一个登录窗口。用户输入登录详细信息,这些详细信息是按如下方式发送到服务器:

$.ajax({
            url: href,
            dataType: 'json',
            type: 'POST',
            data: form.serializeArray(),
            success: function (json, textStatus, XMLHttpRequest) {
                json = json || {};
                if (json.success) {
                    switch (action) {
                        case "xxx":
                        <more code here>
                        default:
                            location = json.redirect || location.href;
                    }
                } else {

当我跟踪代码时,我看到它转到以"位置="开头的行。 我看到 json.redirect 设置为null 和 location.href 设置为当前 URL。

我希望它重定向到正确的 URL,但是当我允许代码继续时,它什么也没做,而且不会转到任何新 URL。

我是否在重定向方式中遗漏了某些内容?

已经有一段时间了,但是您不需要使用window.location而不仅仅是location吗?