Home >Web Front-end >JS Tutorial >Summary of 5 ways Ajax solves caching

Summary of 5 ways Ajax solves caching

亚连
亚连Original
2018-05-23 10:38:131760browse

Below I will bring you a summary of 5 ways to solve caching using Ajax. I will share it with you now and give it as a reference

1. Add anyAjaxObj.setRequestHeader(“If-Modified-Since”,”0″) before sending the ajax request.

2. Add anyAjaxObj.setRequestHeader(“Cache-Control”, “no-cache”) before sending the request via ajax.

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 what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Ajax transfers JSON example code

ajax uses json to realize data transmission

Ajax verification for duplicate implementation code

The above is the detailed content of Summary of 5 ways Ajax solves caching. 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