【问题标题】:after browser go back jquery Get doesn't fire浏览器返回后 jquery Get 不会触发
【发布时间】:2014-12-09 23:35:39
【问题描述】:

简化,在我的第一页,我有这个:

$(function () {
    check();
})
function check() {
    $.get("/MyController/MyAction/", function (data) {
        if(data != undefined && data != "")
        {
            window.location.href = data;
        }
    })
}

这很好用,但是如果用户返回页面(使用浏览器返回按钮)jquery get 函数不会到达控制器并且数据变量是空白的。 为什么 jquery get 函数不执行我的控制器操作? 我使用 ajax 也有同样的结果:

$.ajax({
    url: "/MyController/MyAction/",
})
.done(function (data) {
    if(data != undefined && data != "")
    {
        window.location.href = data;
    }     
});

【问题讨论】:

标签: javascript jquery ajax asp.net-mvc


【解决方案1】:

当您使用后退按钮时,大多数浏览器会从缓存中加载页面。

为防止这种情况,您可以使用 Cache-Control HTTP 标头:

Cache-Control: no-cache, max-age=0, must-revalidate, no-store

How to Defeat the Browser Back Button CacheHTTP Caching FAQ

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-27
  • 2011-03-20
  • 2020-04-18
  • 1970-01-01
  • 2020-11-06
相关资源
最近更新 更多