Javascript getResponseHeader()返回null
我创建了一个名为Javascript getResponseHeader()返回null,javascript,ajax,xmlhttprequest,mime-types,Javascript,Ajax,Xmlhttprequest,Mime Types,我创建了一个名为application/x-mytype的自定义MIME类型,扩展名为.mytype。然后,我在我的服务器中创建了一个名为test.mytype的文件,我试图通过XMLHttpRequest获取它的内容类型,但看起来浏览器无法检测到它 var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest()
application/x-mytype
的自定义MIME类型,扩展名为.mytype
。然后,我在我的服务器中创建了一个名为test.mytype
的文件,我试图通过XMLHttpRequest
获取它的内容类型,但看起来浏览器无法检测到它
var xmlhttp;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET", "https://{myserver}/test.mytype", true);
xmlhttp.send(null);
xmlhttp.onreadystatechange = function (oEvent) {
if(xmlhttp.readyState==4) {
var contentType = xmlhttp.getResponseHeader('content-type');
console.log(contentType); // prints null
if(contentType === 'application/x-mytype') {
// never arrives here
}
}
};
如果我通过Windows资源管理器查看我的“文件类型”,我可以看到我的自定义类型,因此它正在查看Windows注册表。我是否需要设置其他内容,或者浏览器不应该识别我的自定义MIME类型?尝试
内容类型“
仍然没有成功@Bergi