Mostly in Ajax scenarios where cookies are used.
For example: Angularjs's $http ({"url": URL, "method": "GET", Withcredentials ": true}"). Success (function () {})
When a GET request cannot get the correct data, look at the console first.
If the request is from the cache or from a cached
You will find that the request header for the GET request is empty.
An empty request is sent to the server, causing the server to not get your cookie so that it cannot return the required information based on the cookie.
Here's how to fix it:
1. Follow the link with a random index string, such as a timestamp or something. All of them know the pit.
Take angular as an example:
//time Stamp$http ({url:myConstant.sqlUrl+ "/uid" + "time=" + (+NewDate ()), Method:"GET", Withcredentials:true, //allow cookies to be carriedheaders: {"If-modified-since": 0 } //Avoid GET request caching}). Success (function(data) {$scope. UserInfo=Data.data;});//Random number$http ({url:myConstant.sqlUrl+ "/uid" + "time=" +Math.random (), Method:"GET", Withcredentials:true, //allow cookies to be carriedheaders: {"If-modified-since": 0 } //Avoid GET request caching}). Success (function(data) {$scope. UserInfo=Data.data;});
2. Write the block cache directly in the header: {"if-modified-since": 0}
Take angular as an example:
$http ({url:myConstant.sqlUrl + "/uid", Method: "GET", withcredentials:true,//is allowed to carry Cookieheaders: {"If-modified-since" : 0}//avoid GET request cache}). Success (function (data) {$scope. UserInfo = Data.data;});
3. Using the header function of PHP
Header (' Cache-control:no-cache, Must-revalidate ');
About the pit of the GET request cache in IE and Edge browser.