【发布时间】:2018-09-16 10:46:31
【问题描述】:
这是我的 AJAX 函数:
function ajax(url, data) {
return new Promise((resolve, reject) => {
$.ajax({
url: "https://xxx",
data: data,
method: 'POST',
timeout: 50000,
cache: true,
ifModified: true,
crossDomain: true,
success: (data, textStatus, jqXHR) => {
if (data == '@fail@') reject(data);
else {resolve(data);}
},
error: (jqXHR, textStatus, errorThrown) => {
reject(errorThrown);
}
});
});
}
正如在 Chrome -> Network(F12) 中观察到的,这是来自服务器的响应标头:
HTTP/1.1 200 OK
X-Powered-By: Express
Access-Control-Allow-Origin: *
Content-Type: text/html; charset=utf-8
Content-Length: 3
ETag: W/"3-R7zlx09Yn0hn29V+nKn4CA"
Date: Fri, 06 Apr 2018 11:39:41 GMT
Connection: keep-alive
请求标头始终相同,即使在后续调用中也是如此:
POST /register HTTP/1.1
Host: xxx:60001
Connection: keep-alive
Content-Length: 0
Accept: */*
Origin: http://localhost:8000
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
Referer: http://localhost:8000/index.html
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Chrome 不应该在收到 ETag 标头后缓存资源并在后续调用同一 URL 时设置“If-None-Match”标头吗?由于返回的内容相同,我不应该获得 304 而不是 200 的状态码吗?
虽然有时调用其他服务器(例如 Google 地图服务器)中的资源确实会返回 304。
【问题讨论】:
-
我刚刚意识到,如果我将请求方法从 POST 更改为 GET,ETag 机制将按预期工作。那么 ETag 是否仅适用于 GET 请求?
标签: http express caching http-headers etag