json将缓存设置为false

json将缓存设置为false

本文介绍了D3.json将缓存设置为false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到用json调用重新绘制D3元素( d3.json )不希望在IE9 +上更新。原因是json调用被缓存,因此浏览器不会在新数据传递时注册。正常jQuery ajax调用的解决方法是将其属性设置为cache:false,全局用于所有ajax调用:

I noticed that redrawing D3 elements with its json call (d3.json) don't want to be updated on IE9+. The reason for it is that json calls gets cached so the browser doesn't register as new data has been passed. Workaround for normal jQuery ajax calls is to set its property to cache: false, globally for all ajax calls:

$.ajaxSetup({ cache: false });

但如何将其添加到 d3.json 调用,因为它使用自己的方法来调用ajax?我成功地在路径之后添加当前时间戳:

But how can I add it to d3.json calls, since its using own method for calling ajax? I succeeded with adding current timestamp after path:

var noCache = new Date().getTime();
d3.json(data + "?_=" + noCache)

但这是有点蹩脚的方式来做...任何建议我怎么能做到这一点?或者甚至更好,如何在IE运行时设置它:)

but that is a bit lame way to do it... any suggestions how can I accomplish this? Or even better, how to setup this only if IE is running :)

推荐答案

我遇到了同样的问题。
我通过将此代码添加到html文档的HEAD来解决它。

I had the same issue.I solved it by adding this code to the HEAD of the html document.

<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="pragma" content="no-cache">

但是,这会阻止某个页面中每个对象的缓存,所以要小心图像,字体和其他。

However, this will prevent the caching of every object in a certain page, so be careful with images, fonts and others.

这篇关于D3.json将缓存设置为false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 07:04