我想看看标题是 text/html 还是 text/xml.如果它是 text/html 则有一个错误,我宁愿在继续之前抓住它.
I would like to see whether the header was text/html or text/xml. If it was text/html then there was an error and I would rather catch that before proceeding.
使用 getResponseHeader() 方法.
小例子:
<script>
function hand () {
console.log(this.getResponseHeader('content-type'));
}
var x = new XMLHttpRequest();
x.onreadystatechange = hand;
x.open('GET', 'index.html', true);
x.send();
</script>
这篇关于从 XHR 获取响应 Content-Type 标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!