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 ");