Jquery $. getJSON solution to cache problems in IE, jquery. getjson

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.