繁体   English   中英

Ajax调用完成后如何重定向到另一个页面

[英]How to redirect to another page after ajax call is finished

我通过使用JQuery ajax调用来调用void方法,如下所示:

var options = {

    url: "/Account/Login",
    data: formvalues,
    type: "post"
};

$.ajax(options).done(function () {

// how to redirect the user to home page?

});

我想在用户登录后将其重定向到主页。有没有办法在jQuery中完成此操作? 我尝试了window.location.replace ,但是它只是显示页面而不保留任何历史记录。 还有其他方法吗?

您应该能够设置window.location

window.location = '/Home/Index';

澄清:

尽管Window.location是只读的Location对象,但是您也可以为其分配DOMString。 这意味着您可以使用位置工作就好像它是在大多数情况下的字符串:位置=“ http://www.example.com ”是location.href =“的代名词http://www.example.com ” 。

https://developer.mozilla.org/zh-CN/docs/Web/API/window.location

// similar behavior as clicking on a link
window.location.href = "http://stackoverflow.com";

这里找到答案。

使用windows.location.href代替

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM