$.getJSON returning cached data in IE8

前端 未结 7 1439
隐瞒了意图╮
隐瞒了意图╮ 2020-11-29 16:38

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

7条回答
  •  隐瞒了意图╮
    2020-11-29 17:12

    Just to let you know, Firefox and Chrome consider all Ajax request as non-cachable. IE (all versions) treat Ajax call just as other web request. That's why you see this behavior.
    How to force IE to download data at each request:

    • As you said, use 'cache' or 'nocache' option in JQuery
    • Add a random parameter to the request (ugly, but works :))
    • On server side, set cachability (for example using an attribute, see below)

    Code:

    public class NoCacheAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuted(ActionExecutedContext context)
        {
            context.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        }
    }
    

提交回复
热议问题