如何在 jquery 调用后刷新页面

how to refresh the page after jquery call

本文关键字:刷新 调用 jquery      更新时间:2023-09-26

我试图在清除cookie后将用户带到登录页面。我正在对我的控制器进行 jquery 调用以清理 cookie,但我不知道如何将他重定向到登录页面。

我目前在我的 javascript 中有这段代码:

    function()
    {
    $.post('/Home/Action', function(result) {
                                    });
              window.location="login";
      }
public Action()
{
    cookie cleaning code;
}

但问题是令人耳目一新,饼干清洁同时完成。我想在清理饼干后带用户。

谢谢

为什么你把window.location放在$.post回调之外?试试这个:

function() {
    $.post('/Home/Action', function(result) {
        window.location.href = "login";
    });
}
function CleanCookiesAndGotoLogin()
{
    $.post('/Home/Action', function(result) {
         //you put the relocation here so that it waits for the callback
        window.location="/ControllerName/ActionName";
    });
};