1

Simplifying, in my First page, I have this:

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

this works well, but if the user comes back on the page (using browser go back button) the jquery get function doesn't reach to the controller and the data variable is blank. Why jquery get function doesn't execute my controller action? I have the same result using ajax:

$.ajax({
    url: "/MyController/MyAction/",
})
.done(function (data) {
    if(data != undefined && data != "")
    {
        window.location.href = data;
    }     
});
DevT
  • 1,411
  • 3
  • 16
  • 32
  • Sounds like a caching issue to me. See [How to Defeat the Browser Back Button Cache](http://blog.55minutes.com/2011/10/how-to-defeat-the-browser-back-button-cache/) – JDB Dec 09 '14 at 15:33
  • 1
    Probably a caching issue. You can set headers on your page to ensure it is not cached. Have a look at http://stackoverflow.com/questions/49547/making-sure-a-web-page-is-not-cached-across-all-browsers – juju Dec 09 '14 at 15:35

1 Answers1

3

Most browsers load pages from the cache when you use the back button.

To prevent this, you can use the Cache-Control HTTP Header:

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

See How to Defeat the Browser Back Button Cache and HTTP Caching FAQ

JDB
  • 25,172
  • 5
  • 72
  • 123
  • 1
    Thank you! I used this: http://stackoverflow.com/questions/11573803/how-to-disable-cache-of-browser-in-asp-net-mvc-3 – DevT Dec 09 '14 at 15:57