使用window.location.replace()重定向AJAX成功 [英] Redirection on AJAX success using window.location.replace()
本文介绍了使用window.location.replace()重定向AJAX成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试重定向页面上成功的ajax调用,以下代码工作正常,
I am trying to redirect the page on the successful ajax call, the following code works fine,
$.ajax(
{
type: "POST",
url: path,
data: response1,
contentType: "application/json",
success: ->
window.location.replace("http://172.16.17.141:81/configuration/manage_users")
});
这种方法的问题是,我给的路径是固定的, p>
Problem with this approach is that the path I am giving is fixed, I want something like,
$.ajax(
{
type: "POST",
url: path,
data: response1,
contentType: "application/json",
success: ->
alert(window.location.host + "/configuration/manage_users")#Gives right path
window.location.replace(window.location.host + "/configuration/manage_users")
#Does not work, I even tried window.location.host.toString()
});
页面不按上述方法重定向,而是URL重定向到about :
The page does not redirect with the above approach and instead of the URL, the page redirects to "about:blank".
推荐答案
问题是我没有指定协议,
The problem was that I was not specifying the protocol,
window.location.replace(window.location.protocol + "//" +
window.location.host + "/configuration/manage_users")
,我发现,
window.location = window.location.protocol + "//" +
window.location.host + "/configuration/manage_users"
更适合重定向。
这篇关于使用window.location.replace()重定向AJAX成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文