从XHR获取响应Content-Type标头 [英] Get the response Content-Type header from XHR

查看:283
本文介绍了从XHR获取响应Content-Type标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想看看标题是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.

推荐答案

使用最小示例:

<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标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆