使用window.location.replacement()重定向AJAX成功
Redirection on AJAX success using window.location.replace()
我正在尝试在成功的ajax调用上重定向页面,下面的代码运行良好,
$.ajax(
{
type: "POST",
url: path,
data: response1,
contentType: "application/json",
success: ->
window.location.replace("http://172.16.17.141:81/configuration/manage_users")
});
这种方法的问题是,我给出的路径是固定的,我想要类似的东西
$.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()
});
页面不使用上述方法重定向,而是重定向到"about:blank",而不是URL。
任何帮助都将不胜感激。
问题是我没有指定协议
window.location.replace(window.location.protocol + "//" +
window.location.host + "/configuration/manage_users")
运行良好,我发现
window.location = window.location.protocol + "//" +
window.location.host + "/configuration/manage_users"
更适合重定向。
通常您可以在服务器上执行此操作。您必须响应正确的HTTP标头。您的后端技术是什么?在node.js中,它看起来是这样的:
var host = 'http://172.16.17.141:81'
response.writeHead(302, {
'Location': host + '/configuration/manage_users'
});
response.end();
这样行吗?
$.ajax
type: 'POST'
url: path
data: response1
contentType: 'application/json'
success: ->
window.location = "//#{window.location.host}/configuration/manage_users"
相关文章:
- AJAX不会在文件上传后重定向到网页-POST方法
- 我尝试在登录脚本中使用ajax,但页面不会重定向
- 如何使用Ajax调用特定的控制器和操作来重定向用户
- ASP.NET MVC 3-在ajax调用后,重定向到新页面或生成页面刷新
- 当达到codeigniter/tank auth会话超时时,在ajax调用中处理php重定向
- 使用ajax进行HTML重定向
- 为什么AJAX调用有时会重定向页面
- 单击事件中的ajax请求后重定向
- 在AJAX调用中获取重定向的php页面名称
- 如何在ajax重定向中传递create-formbuilder
- 将对Ajax PUT的json响应重定向到要由EL解析的JSP中
- 从Ajax脚本重定向Javascript页面
- 如何通过ajax调用将用户重定向到页面
- Rails:通过调用Ajax重定向
- 下拉菜单重定向使用AJAX和JQuery或Javascript
- ajax表单提交后从客户端重定向
- 使用window.location.replacement()重定向AJAX成功
- Internet Explorer没有't重定向ajax响应
- 在Javascript中,如何在窗口位置重定向Ajax响应
- 在 PHP 中重定向 AJAX 调用