为了节省服务器资源,我正在寻找一种使用 javascript 检索给定 url 的内容类型的方法。它不应仅从标题下载 URL 的完整内容。 javascript 有限制吗?
使用 head 请求进行 Ajax 调用。
var url = window.location.href;
var xhttp = new XMLHttpRequest();
xhttp.open('HEAD', url);
xhttp.onreadystatechange = function () {
if (this.readyState === this.DONE) {
console.log(this.status);
console.log(this.getResponseHeader("Content-Type"));
}
};
xhttp.send();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)