Recently, I made an Ajax-related function. The goal is to generate different welcome languages based on different login statuses of users, as shown below:
When the user logs in, it will show: Hello, come again!
If the user does not log on, it will show that you have not logged on!
After I wrote Ajax, I found a fatal problem:
Everything works in Firefox, but it's okay to open ie for the first time. If you refresh it again, Chinese characters will become garbled!
I checked it carefully and did not get any results. Later, with the help of laruence, I found it was an IE cache problem.
OK. The problem is as follows:
Principle:
Every time Firefox requests, it will return to the server again to obtain the latest data, but IE will be different, it will cache
Only the first request will actually read the data from the server, so that the Ajax data will not be updated over time ....
I opened the cache folder of IE and found a file named after the Ajax request address. When I opened it, I realized why it was garbled, because the file is stored in ANSI. Maybe IE will not use the GBK encoding format to read this file, but will use Unicode
Solution (collected from the Internet ):
1,AddHeader ("cache-control: No-cache, must-revalidate"); or use the following combination to make it better:
Header ( " Expires: sat, 1 Jan 2005 00:00:00 GMT " );
Header ( " Last-modified: " . Gmdate ( " D, D m y h: I: S " ) . " GMT " );
Header ( " Cache-control: No-cache, must-revalidate " );
Header ( " Pragma: No-Cache " );
2 , in Ajax Add XMLHttpRequest. setRequestHeader ("If-modified-since", "0");
3 , in Ajax Add XMLHttpRequest. setRequestHeader ("cache-control", "No-Cache");
4 , in Ajax URL Add "? Fresh = "+ math. random (); // Of course, here the parameter fresh Any
5 , the fourth method is similar to the third method, in URL Add "? Timestamp = "+ new date (). gettime (); // This method is recommended. I use this method and I personally think it is more convenient.
6,UsePostSubstitutionGet: Not recommended