How jquery handles ajax caching issues: 1. Directly set [$.ajaxSetup({cache: false})]; 2. Change the type to post and set a parameter [data: 'a= b'].
Recommended: "jquery video tutorial"
How jquery handles ajax caching problems:
1. Add a random number to the request link. If you are using jQuery, set it directly: $.ajaxSetup({cache: false});
2. Change the type to post, and set any parameter data: 'a=b'
(Be sure to set the parameters, otherwise it will still be cached)
3. Talk about the different generation For the number, use random numbersMath.random();
ortimestamp 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); } });
Later I found many AJAX GET requests on the Internet that will be cached. Let me summarize the solution
1. Add header(" Cache-Control: no-cache, must-revalidate”);
2. Add anyAjaxObj.setRequestHeader(“If-Modified-Since”,”0″ before sending the ajax request );
3. Add anyAjaxObj.setRequestHeader(“Cache-Control”,”no-cache”);
4 before sending the ajax request , add "?fresh=" after the Ajax URL parameter Math.random(); //Of course, the fresh parameter here can be chosen arbitrarily
5. The fourth method is similar to the third method, in the URL Add "?timestamp=" new Date().getTime();
6. Use POST instead of GET: Not recommended
Related free learning recommendations: JavaScript(Video)
The above is the detailed content of How jquery handles ajax caching issues. For more information, please follow other related articles on the PHP Chinese website!