好的,我可以使用
访问 HTTP ajax 响应 headerxhr.getAllResponseHeaders();
但它似乎没有得到日期,尽管它在那里:
[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);
}
});
有没有办法在响应 header 中获取日期?
最佳答案
您可能正在制作 CORS 的情况出于安全原因,请求和 header 被过滤掉。
另见关于 missing response headers in ajax request 的类似问题. 解决方案可能是在服务器响应中设置此 HTTP header :
Access-Control-Expose-Headers: Date
关于javascript - 从 http header 响应中获取日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27968368/