Home > Web Front-end > JS Tutorial > 2 solutions to xmlhttp cache clearing_javascript skills

2 solutions to xmlhttp cache clearing_javascript skills

WBOY
Release: 2016-05-16 17:09:22
Original
1256 people have browsed it

Method 1: Add If-Modified-Since header
When xmlhttp is called multiple times, it always displays the cached page. Try adding the corresponding header in php or asp. The http header explicitly does not want to be cached, but it has no effect!!

Now I finally found a way, which is to send a If-Modified-Since header after xmlhttp.open. The code is as follows
xmlhttp.setRequestHeader('If-Modified- Since', '0');
xmlHttp.onreadystatechange = stateChanged;
, '0');
xmlHttp.send(null);

Method 2: Add change parameters after the request URL

Because IE caches the same URL request by default, the URL is added with unique parameters as a distinction. Keeping the URL of each request different can bypass the IE cache problem

js: URL = "http ://host/a.php" "?" Math.random();
vbs: URL = "http://host/a.php"&"?"&Timer()

//var url = "ResponseContentPageScore.aspx?key=" Math.round(Math.random() * 100) "&HotelCD=" inputContent;

var url = "ResponseContentPageScore.aspx?key=" new Date ().getTime() "&HotelCD=" inputContent;

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template