When using jquery Ajax non-flush submission to determine the value in the input box, it is found that the effect is not correct because of the caching problem;
Workaround:
Browser resolution (not recommended):
* Clear the browser cache in Internet Options
* Clear the cache in the F12 developer tool
PHP Code Workaround:
When Ajax T commits, it does not allow the generation of caches;
1, to the request link plus random number, if using jquery, directly set: $.ajaxsetup ({cache:false});
2, change the type to post, and arbitrarily set a parameter data: ' A=b ' (be sure to set the parameters, otherwise it will still be the cache)
3, said to generate a different number, the random number math.random (); or a timestamp + new date ();
Example
The code is as follows |
|
$.ajax ({ Type: "GET" URL: ' test.html ', Cache:false, DataType: "HTML", Success:function (msg) { Alert (msg); } }); Or $.ajax ({ Type: "GET" URL: ' test.html? ' +math.random (), Cache:false, DataType: "HTML", Success:function (msg) { Alert (msg); } }); |
A lot of Ajax get requests that were found on the web were then summed up by the caching workaround.
1, add header on the service side ("Cache-control:no-cache, must-revalidate");
2, add Anyajaxobj.setrequestheader ("If-modified-since", "0″") before Ajax sends the request;
3, add Anyajaxobj.setrequestheader ("Cache-control", "No-cache") to Ajax before sending the request;
4, after the URL parameter of Ajax add "? fresh=" + math.random ();//Of course, here the parameters fresh can be arbitrarily taken
5, the fourth method and a third similar, after the URL parameter with "? timestamp=" + N EW Date (). GetTime ();
6. Replace get with post: not recommended