简体   繁体   中英

How to store the data in cache when data load from AJAX and PHP

When a user clicks on a button we are making an ajax call, the data came and we display the data in a div. Then user click on another button again making an ajax call and data load respective to that div, but when I click on the previous button I want that it should not make an ajax call it should pick the data from the cache. How can I do this? Please help me out on this.

Thank!!

Use localStorage, simple set the storage, and then get the storage and do a logic check.

Something like below in sudo:

localStorage.setItem("id", "stuff");

localStorage.getItem("id");

logic check

It would much clearer if you posted your code. Anyways, you can assign the old data to the previous ajax call from the second button now calling the second ajax request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM