Today, when I requested data from the backend server without refreshing the ajax page, I encountered Ajax cache in IE. Both FF and Chrome are normal, because I didn't know that IE had this bad problem at the beginning, finally solve the problem.
By default, IE caches the Ajax request results for the request address. In other words, before the cache expires, multiple Ajax requests initiated for the same address will only be sent to the server for the first time. In some cases, this default caching mechanism is not what we want (such as obtaining real-time data ).
When Ajax is used in IE to request a page, the previous result is usually returned due to cache, causing confusion (for example, multiple requests but no response ).
Problem reproduction:
Window. setInterval (realtimeHandle, 3000 tempCounter = (dbCounter! = TempCounter & tempCounter! = "Too many threads have been written, too many threads have been written, too many threads have been written! Now Count = "+ =" json"
[That is, when the get method is used, the IE browser retrieves data from the cache because the sending parameters and addresses are consistent, instead of requesting the server, the post method does not cause this problem because of different parameters.]
But this does not happen in FF and Chrome.
Solution:
IChange
Internet Options -- browsing history -- settings -- the option of Temporary Internet Files is changed to the option that can be used to access the webpage each time.
Add a random function after the page of the AJAX request. For example, we can use a random time function. Add it after the URL sent by javascript.
Random Function Code example:
randomString = "?r=" ( i = 0; i < 20; i+++= Math.floor(Math.random() * 10
For example:
URL + "&" + "t =" + Math. random (); // or new Date ();
"? Timestamp = "+ new Date (). getTime ();
In addition, we can also set it as follows:
$. AjaxSetup ({
})
In fact, this mechanism of jQuery is also implemented by adding different query string suffixes to the request address.