How to obtain cached pages through Ajax

Source: Internet
Author: User

In this case, the local cache is checked before Ajax is obtained. If the local cache already contains the same content, the remote server is not accessed. This operation can increase the speed and reduce the pressure on the server. But the disadvantages are also obvious.

To solve this problem. We must add an additional parameter to the get page. A simple method is to use a random number.

Example:

CopyCode The Code is as follows: function idcheck () {// The parameter calls the function.
VaR F = Document. modify_form;
VaR book_num = f. book_num.value;
If (book_num = ""){
Window. Alert ("the book number cannot be blank ");
F. book_num.focus ();
Return false;
}
// Add a random number //////////////////////////////
VaR number = math. Random ();
Number = Number * 1000000000;
Number = math. Ceil (number );
//////////////////////////////////////// //
Send_request ('get _ book. php? Book_num = '+ book_num +' & ranum = '+ number); // The following "ranum = Number" is added.
}

This avoids the problem of returning the same content on the page with the same parameters.

Another way is to add code to the called page to prevent this page from being cached.

Htm webpageCopy codeThe Code is as follows: <metahttp-equiv = "Pragma" content = "no-Cache">
<Metahttp-equiv = "cache-control" content = "no-cache, must-revalidate">
<Metahttp-equiv = "expires" content = "wed, 26feb199708: 21: 57gmt">

Or <metahttp-equiv = "expires" content = "0">
ASP Web PageCopy codeThe Code is as follows: Response. expires =-1
Response. expiresabsolute = now ()-1
Response. cachecontrol = "no-Cache"

PHP webpageCopy codeThe Code is as follows: Header ("expires: Mon, 26jul199705: 00: 00gmt ");
Header ("cache-control: No-cache, must-revalidate ");
Header ("Pragma: No-Cache ");

JSP webpageCopy codeThe Code is as follows: Response. addheader ("Pragma", "No-Cache ");
Response. addheader ("cache-control", "No-cache, must-revalidate ");
Response. addheader ("expires", "0 ");

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.