Jquery $. getJSON solution to cache problems in IE, jquery. getjson
In work, the data on the home page that implements Ztree is the JSON object returned by the background.
Because the tree is fixed, every time the tree is refreshed
$. The URLs of getJSON are all the same. I modified or added the tree node, and then refreshed the tree IE. No changes have been made in other browsers.
This makes me Tangle
Then I searched for the information on the Internet and found the solution.
Solution:
The $. getJSON request of Jquery has a caching mechanism, that is, when the same URL is requested to access the background, it directly retrieves data from the cached data on the page instead of the background data.
So we need to change a URL.
This is our URL var url = "XXXX/XXX"
The following describes how to generate a random number.
Copy codeThe 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 codeThe Code is as follows:
Var I = getrandomnumnum (1,100 );
Url = url + "& random =" + I;
Then we can wear the URl to solve the problem.
Aspnet, jquery, $ getjson () Why does the Internet Explorer retrieve data for the first time?
Add a random number to your url.
Var url = 'ajax/Ajax. ashx? T = AdminMSG & R = abc & random = '+ Math. random ();
$ GetJSON () of jquery
What about cache? 'getdate. do? Id = 100 '. You can just upload a different object each time, like this:
'Getdate. do? Id = 100 & t = '+ Math. random ()
It uses a random number or a new Date () timestamp.