好了,所以我可以访问使用从HTTP标头响应获取日期
xhr.getAllResponseHeaders();
的HTTP Ajax响应头,但它似乎并没有得到它的日期,但它的存在:
[Chrome]
**Response Header**
Access-Control-Allow-Origin:*
Cache-Control:no-cache
Content-Length:8092
Content-Type:application/json; charset=utf-8
**Date:Thu, 15 Jan 2015 16:30:13 GMT**
Expires:-1
Pragma:no-cache
Server:Microsoft-IIS/8.0
TotalCount:116
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET
和代码只能说明这一点:
[output on alert xhr.getAllResponseHeaders();]
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
这里的Ajax调用:
$.ajax({
url: url,
type: "GET",
contentType: "application/json;charset=utf-8",
async: true,
success: function (data,status, xhr) {
displayNewData(data);
alert(xhr.getAllResponseHeaders());
},
error: function() {
alert(url);
}
});
有没有一种方法可以在响应头中获取日期?
它不会工作,因为你不能访问日期字段使用'getAllResponseHeaders'或'getResponseHeader()' Chrome抛出一个错误“拒绝获取不安全的标题”日期”' – stefbach 2015-09-30 05:33:26