为什么我的 jQuery ajax 不支持ETag功能?
您在第二个示例中看到,没有“If-None-Match”标头。但为什么?
在两个经过测试的浏览器中,我有一个 50% 的更改,有一个缓存将按 F5,但只需通过单击链接重新打开页面,它就不起作用。
不工作 jQuery 示例
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
console.log( xmlhttp.responseText );
}
}
xmlhttp.open("GET","/energyManagerSensor/getCleanData/sensor_id/4?shrink_type=day&from=18.11.2011&to=23.02.2013",true);
xmlhttp.send();
请求标头
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7,de-CH;q=0.6,fr-FR;q=0.5,fr;q=0.4,en-gb;q=0.3,sr-RS;q=0.2,sr;q=0.1
Cache-Control max-age=0
Connection keep-alive
Cookie PHPSESSID=iie173rsc5bqggll6uhmg6m7i6
Host sfportal3_hh_dev
If-Modified-Since Tue, 12 Feb 2013 0:0:0 GMT
If-None-Match 4SdayF1321570800T1361574000
Referer http://sfportal3_hh_dev/energyManagerDisplay/view/display_id/1
User-Agent Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0 FirePHP/0.7.1
x-insight activate
响应标题
Cache-Control max-age=3600
Connection close
Date Tue, 12 Feb 2013 06:16:23 GMT
Expires Thu, 19 Nov 1981 08:52:00 GMT
Server Apache/2.2.22 (Ubuntu)
不工作的 jQuery 示例
$.ajax({
url: "/energyManagerSensor/getCleanData/sensor_id/4?shrink_type=day&from=18.11.2011&to=23.02.2013",
type: 'GET',
dataType: "json",
cache: true,
ifModified: true,
success: function(return_data) {
console.log(return_data);
}
});
请求标头
Accept application/json, text/javascript, */*; q=0.01
Accept-Encoding gzip, deflate
Accept-Language de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7,de-CH;q=0.6,fr-FR;q=0.5,fr;q=0.4,en-gb;q=0.3,sr-RS;q=0.2,sr;q=0.1
Connection keep-alive
Cookie PHPSESSID=iie173rsc5bqggll6uhmg6m7i6
Host sfportal3_hh_dev
Referer http://sfportal3_hh_dev/energyManagerDisplay/view/display_id/1
User-Agent Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0 FirePHP/0.7.1
X-Requested-With XMLHttpRequest
x-insight activate
响应标题
Cache-Control max-age=3600
Connection Keep-Alive
Content-Type text/json
Date Tue, 12 Feb 2013 06:18:41 GMT
Etag 5SdayF1321570800T1361574000
Expires Tue, 12 Feb 2013 07:02:18 GMT
Keep-Alive timeout=5, max=74
Last-Modified Tue, 12 Feb 2013 0:0:0 GMT
Server Apache/2.2.22 (Ubuntu)
Transfer-Encoding chunked
X-Powered-By PHP/5.3.10-1ubuntu3
测试环境
- 火狐 18.0.2
- 铬 24.0