$ .getJSON返回在IE8中缓存数据 [英] $.getJSON returning cached data in IE8

查看:168
本文介绍了$ .getJSON返回在IE8中缓存数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在玩弄ASP.net MVC和JQuery在时刻。我已经遇到水煤浆这似乎没有什么意义。

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.

我打电话jQuery的 $。的getJSON 函数来填充一些div的。该事件被触发的 $(文件)。就绪事件。这完美的作品。

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

有一个小 AJAX.BeginForm 填充层时这又增加了价值使用。它正确地调用远程功能,在成功调用原始的javascript函数重新填充的div。

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.

下面是怪异的一部分:在Firefox和Chrome - 一切正常。但在IE8(测试版)第二次调用填充事业部脚本(调用$ .getJSON函数)获取缓存数据并不会向服务器!

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!

希望这个问题是有道理的:在坚果壳 - 为什么 $的getJSON 获取缓存的数据?为什么它仅仅影响IE8?

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

推荐答案

只是为了让你知道,Firefox和Chrome考虑所有Ajax请求的非超高速缓存。 IE浏览器(所有版本)处理Ajax调用,正如其他网络的要求。这就是为什么你看到此行为。

如何强制IE浏览器在每次请求下载的数据:

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:


  • 正如你所说,使用缓存或JQuery的非缓存选项

  • 添加一个随机参数的要求(丑,但工程:))

  • 在服务器端,设置缓冲能力(例如,使用一个属性,见下文)

code:

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

这篇关于$ .getJSON返回在IE8中缓存数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆