Setinterval and Ajax-Ajax cache Problems

Source: Internet
Author: User

When you perform the serinterval operation on AJAX, you must add a timestamp after the request address.

Because access to the same URL in a short time will access the cache.

 

VaR interval =Window. setinterval(Function (){
$. Get (".../ajax/calculatetime. aspx? Time = "+ new date (). getmilliseconds (),

{Aid: Aid },

Function (data, status ){
........................................ .......

})
},1000 );

 

I reprinted a question about Ajax caching.Article

Recently I have been working on projects and have encountered cache problems. TIPS. Because the basic requirement is that IE is compatible with Firefox browsers, Firefox has been used for testing and no cache problems have been found. The cache problem occurs in IE.

If the $. for Ajax () method, it is very easy to remove the cache. You only need to configure the cache attribute to false, but if you want to write getjson () in a simple way (), the configuration cannot be used to remove the cache. Because getjson does not have this cache attribute for you to configure. If the called URL is the same as the previous one, the callback function will read data directly in the cache instead of calling the corresponding method in the background.

Knowing the cause, the solution is to make the URL address of each request different, but it does not affect the data required by the requested service, there are several methods:

1. $. getjson ("url? T = "+ new date (), function (JSON) {}); adds a time variable based on the original URL, and the request address is different each time.

2. $. getjson ("url? Rand = "+ math. random, function (JSON) {}); adds a random variable to the original URL. However, this method is risky. In case the random number is the same ......

3. The third method is to define an incremental variable. Add this variable after the URL. After each request is complete, the variable increments accordingly.

$. Get () the cache removal method is the same as $. getjson ().

 

Reference blog: http://user.qzone.qq.com/935937284/blog/1329985097

Related Article

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.