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:
Copy codeThe Code is as follows:
Function idCheck () {// call a function with Parameters
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 webpage
Copy 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 Page
Copy codeThe Code is as follows:
Response. expires =-1
Response. expiresabsolute = now ()-1
Response. cachecontrol = "no-cache"
Php webpage
Copy codeThe Code is as follows:
Header ("expires: mon, 26jul199705: 00: 00gmt ");
Header ("cache-control: no-cache, must-revalidate ");
Header ("pragma: no-cache ");
Jsp webpage
Copy codeThe Code is as follows:
Response. addHeader ("pragma", "no-cache ");
Response. addHeader ("cache-control", "no-cache, must-revalidate ");
Response. addHeader ("expires", "0 ");