Home > Article > Web Front-end > Summary of solutions to Ajax caching problems
The caching problem of Ajax is quite annoying, but there are solutions, and there are more than one. You can add a random number or time after the URL. Friends who are interested in ajax come together. Take a look at the summary of solutions to Ajax caching problems!
1. Add anyAjaxObj.setRequestHeader("If-Modified-Since", "0") before sending the ajax request.
2. Add anyAjaxObj.setRequestHeader("Cache-Control", "no-cache") before sending the ajax request.
3. Add a random number after the URL: "fresh=" + Math.random();.
4. Add the time after the URL: "nowtime=" + new Date().getTime();.
5. If you are using jQuery, just do $.ajaxSetup({cache:false}). In this way, all ajax on the page will execute this statement and there is no need to save cache records.
The above is all the content of this article, I hope it will be helpful to everyone!
Related recommendations:
ajax cross-page submission form
Ajax implements partial refresh login interface with verification code
The above is the detailed content of Summary of solutions to Ajax caching problems. For more information, please follow other related articles on the PHP Chinese website!