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

Jquery $.getJSON solution to caching problem under IE_jquery

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

Implement Ztree on the homepage at work. The data of Ztree is the JSON object returned by the background

Because the tree is fixed, the tree is refreshed every time

The URLs of $.getJSON are all the same. Here comes the problem. I modify or add a new tree node and then refresh the tree. There is no change in IE. It is OK in other browsers

This makes me confused

Then I searched the Internet and found the solution

Solution:

Jquery's $.getJSON request has a caching mechanism, that is, when requesting the same URL to access the backend, it will directly retrieve the data from the cached data of the page instead of requesting the backend

So we have to change a URL

This is our URL var url="XXXX/XXX"

Here’s a method to generate random numbers

Copy code The code is as follows:

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

Then change our URL
Copy code The code is as follows:

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

Then just put the URl through it. Problem solved
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