【问题标题】:jQuery Caching in IEIE 中的 jQuery 缓存
【发布时间】:2012-05-21 01:23:16
【问题描述】:

我们在这里有一个使用 Wufoo 表单和 Wufoo jQuery API 的网站。

我们从 API 中提取数据,对其进行排序,然后将其显示在页面上。当我们提交数字高于当前前 10 名的表单时,它应该在右侧实时更新,因为表单会重定向回自身。它这样做,但不是在 IE 中。相反,在提交表单和显示新数据之间似乎存在不必要的延迟。关闭浏览器并重新打开页面似乎可行,但这并没有帮助。

这是我们正在使用的 jQuery:

<script>
    $.wufooAPI.getEntries({
        "callback"   : processEntries,             
        "formHash"   : "x7x1x7",                   
        "sortID"   : "Field3",                   
        "sortDirection"   : "DESC",
    });
    function processEntries(data) {
        $.each(data.Entries.slice(0, 10), function(entriesIndex, entriesObject) {
            // Make sure this entry has all the required bits
            if (entriesObject.Field1 && entriesObject.Field3) {
                $("#attendeeTemplate").tmpl(entriesObject).appendTo("#people ul");  
            }
        });
    };

</script>

这是模板代码:

            <script id="attendeeTemplate" type="text/x-jquery-tmpl">
                <li>
                    <h4>${Field1}</h4>
                    ${Field3} minutes
                </li>
            </script>

它在除 IE8 和 9 之外的所有浏览器中都能完美运行,当它看起来像是在缓存数据而不是从服务器拉取请求时。

有什么办法可以停止在 IE 中缓存 jQuery 吗?

【问题讨论】:

  • 您是否尝试过查看 jquery 数据中是否存储了任何内容,api.jquery.com/jQuery.removeData
  • 当您说它看起来像是在缓存时,这是否意味着您看到(在 IE 开发工具中)有一个请求发出并且响应是状态 200(来自缓存)或 304 未修改?服务器是否发送 Expires 或 max-age 标头?客户端发送 max-stale 了吗?浏览器和网络服务器之间是否有任何缓存或代理?

标签: internet-explorer jquery jquery-templates wufoo


【解决方案1】:

一种简单的方法是使用时间戳来欺骗和加盐您的请求网址(但这有点笨拙)。 你可以关掉caching for ajax requests

$.ajaxSetup ({
    // Disable caching of AJAX responses
    cache: false
});

MSDN 在 IE http://support.microsoft.com/kb/234067 中有一个关于缓存避免的页面。

【讨论】:

  • 你是如何解决缓存问题的?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-19
  • 2011-02-20
  • 1970-01-01
  • 2013-06-11
  • 2010-12-20
相关资源
最近更新 更多