从缓存中阻止JQUERY .load [英] Prevent JQUERY .load from cache

查看:97
本文介绍了从缓存中阻止JQUERY .load的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看起来,在IE9中,使用jquery .load将从浏览器缓存中提取数据,因此AJAX加载内容的实时效果不起作用。有没有什么类型的开关强制jquery .load获取数据新鲜?



Thansk!

解决方案

如果您正在使用 $。ajax 低级方法,则禁用缓存的选项在jQuery中可用。这在 load 的简化签名中没有表示。您可以通过确保URL始终是唯一的来代替它。您可以在URL的末尾以毫秒为单位放置当前时间以实现此目的,因为这实际上始终是唯一的:

  url + ='?_ ='+(new Date())。getTime(); 

(这假定 url 是一个字符串包含请求URL,并且当前没有任何查询参数。)


It seems that in IE9, using jquery .load will pull data from the browsers cache and so the 'real time' effect of AJAX loading content isnt working. Is there any kind of switch to force jquery .load to get the data fresh?

Thansk!

解决方案

The option to disable caching is available in jQuery if you are using the $.ajax low-level method. This is not represented in the simplified signature for load. You could mimic it instead, by ensuring that the URL is always unique. You can put the current time in milliseconds on the end of the URL to achieve that, since that will practically always be unique:

url += '?_=' + (new Date()).getTime();

(This presumes that url is a string containing the request URL and that it doesn't have any query parameters currently.)

这篇关于从缓存中阻止JQUERY .load的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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