Home  >  Article  >  Web Front-end  >  Summary of solutions to Ajax caching problems

Summary of solutions to Ajax caching problems

韦小宝
韦小宝Original
2017-12-31 10:21:101487browse

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:

Analysis and solutions to the causes of 415 errors when Ajax transfers json format data to the background

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn