好的,因此我可以使用访问HTTP ajax响应标头
xhr.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); } });
有没有办法可以在响应头中获取日期?
这有帮助:
var req = new XMLHttpRequest(); req.open('GET', document.location, false); req.send(null); var headers = req.getAllResponseHeaders().toLowerCase(); alert(headers);