Ajax cache Problems

Source: Internet
Author: User

When I use ajax to query a database, I only query the database for the first time. I will not submit any more requests to the server for processing.
The cache tag in the page header does not work.

<Meta http-equiv = "Pragma" content = "no-Cache">
<Meta http-equiv = "cache-control" content = "no-Cache">
<Meta http-equiv = "expires" content = "0">

Solution:
1: add the timestamp var url = URL + "& timestamp =" + new date (). gettime ();
2: Add random number var url = URL + "& Ran =" + math. Random (); 1. Prevent reading data from the cache

When Ajax calls the background page, it first determines whether the page exists in the cache. If yes, it takes the value from the cache. The purpose of adding a random number is obvious.
2. Security also plays a role
3: add request. setRequestHeader ("If-modified-since", "0") before request. Send ");

4: Add response. setheader ("cache-control", "No-Cache") before output. Print in the background; clear the cache

Ajax cache Problems

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.