0

我从 Ajax 调用一个方法。该方法返回字符串。方法完成后,我需要重定向 url。

success: function (data) {
                    window.location.href = data;
            }

因此,一开始的 url 是 localhost:1111/Login/Index,如果 data != "" 一切正常。但是,如果 data = "",那么我希望 window.location.href 是 localhost:1111/。现在,window.location.href 是 localhost:1111/Login。这该怎么做?

4

2 回答 2

1

您可以按如下方式创建 URL:

success: function (data) {
    if (data == "") {
        data = window.location.protocol + "//" + window.location.host;
    }
    window.location.href = data;
}
于 2012-05-14T10:33:39.900 回答
0

在没有主机的情况下发送 url,然后使用:

window.location.href = window.location.protocol + "//" + window.location.host +"/"+data
于 2012-05-14T10:30:11.760 回答