Home > Web Front-end > JS Tutorial > body text

Jquery $.getJSON 在IE下的缓存问题解决方法_jquery

WBOY
Release: 2016-05-16 16:34:23
Original
1274 people have browsed it

在工作中主页实现Ztree Ztree的数据是后台返回的JSON对象

因为树是固定的所以每次刷新树

$.getJSON 的url都是相同的 问题来了 我修改 或者 新增树节点 然后刷新tree IE竟然毫无变化 在其他浏览器上面都OK

这让我纠结了

然后在网上搜索了一下资料发现 解决办法

解决办法:

Jquery 的 $.getJSON请求有一个缓存机制 就是在请求相同URL访问后台时候 他会直接从页面缓存的数据中取出来数据 而不是请求后台

所以我们要改变一个URL

这是我们的URL var url =“XXXX/XXX”

下面来一个 生成随机数的方法

复制代码 代码如下:

function GetRandomNum(Min,Max)
{
var Range = Max - Min;
var Rand = Math.random();
return(Min + Math.round(Rand * Range));
}

然后改变我们的URL
复制代码 代码如下:

var i=GetRandomNum(1,100);
url=url+“&random=”+i;

然后把URl穿进去就可以了 问题解决
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!