About the pit of the GET request cache in IE and Edge browser.

Source: Internet
Author: User

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.

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.