是否可以使用某种JavaScript来更改或设置HTTP请求的标头?
只使用 JavaScript 和像 dojo/jQuery 这样的框架......
有没有办法找到特定文件扩展名的内容类型?
假设我输入字符串“something.pdf”,我想显示一个提示“application/pdf”
或“something.html”显示“text/html”?
好的,我可以使用访问HTTP ajax响应头
xhr.getAllResponseHeaders();
Run Code Online (Sandbox Code Playgroud)
但它似乎没有得到它的日期,虽然它在那里:
[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
Run Code Online (Sandbox Code Playgroud)
并且代码仅显示以下内容:
[output on alert xhr.getAllResponseHeaders();]
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Run Code Online (Sandbox Code Playgroud)
这是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);
}
});
Run Code Online (Sandbox Code Playgroud)
有没有办法在响应标题中获取日期?
我正在使用一些API,我注意到在响应中我有这个:
我需要阅读"x-dl-units-left",但我得到null:
$.ajax(ajaxConfig).done(function(response, textStatus, xhr){
var left = xhr.getResponseHeader("x-dl-units-left"); //null
var all = xhr.getAllResponseHeaders(); // "content-type: application/json;charset=UTF-8"
});
Run Code Online (Sandbox Code Playgroud)
谁可能知道为什么?:(
谢谢