$.getJSON returning cached data in IE8

2019-01-08 04:05发布

I'm playing around with ASP.net MVC and JQuery at the moment. I've come across behavour which doesn't seem to make sense.

I'm calling JQuery's $.getJSON function to populate some div's. The event is triggered on the $(document).ready event. This works perfectly.

There is a small AJAX.BeginForm which adds another value to be used when populating the divs. It calls the remote function correctly and upon success calls the original javascript function to repopulate the divs.

Here is the weird part: In FireFox and Chrome - Everything works. BUT In IE8 (Beta) this second call to the populate Div script (which calls the $.getJSON function) gets cached data and does not ask the server!

Hope this question makes sense: In a nut shell - Why is $.getJSON getting cached data? And why is it only effecting IE8?

7条回答
Juvenile、少年°
2楼-- · 2019-01-08 04:39

If you're using ASP.net MVC, consider adding an extension method to easily implement no caching like so:

    public static void NoCache(this HttpResponse Response)
    {
        Response.Cache.SetNoStore();
        Response.Cache.SetExpires(DateTime.MinValue);
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Cache.SetValidUntilExpires(false);

        Response.Expires = -1;
        Response.ExpiresAbsolute = DateTime.MinValue;
        Response.AddHeader("Cache-Control", "no-cache");
        Response.AddHeader("Pragma", "no-cache");
    }
查看更多
登录 后发表回答