简化,在我的第一页中,我有这个:
$(function () {
check();
})
function check() {
$.get("/MyController/MyAction/", function (data) {
if(data != undefined && data != "")
{
window.location.href = data;
}
})
}
这很有效,但是如果用户回到页面上(使用浏览器返回按钮),则jquery get函数不会到达控制器并且数据变量为空。 为什么jquery获取函数不执行我的控制器操作? 我使用ajax得到了相同的结果:
$.ajax({
url: "/MyController/MyAction/",
})
.done(function (data) {
if(data != undefined && data != "")
{
window.location.href = data;
}
});
答案 0 :(得分:3)
当您使用后退按钮时,大多数浏览器都会从缓存中加载页面。
为防止这种情况,您可以使用Cache-Control HTTP标头:
Cache-Control: no-cache, max-age=0, must-revalidate, no-store
请参阅How to Defeat the Browser Back Button Cache和HTTP Caching FAQ