Get the response Content-Type header from XHR

蓝咒 提交于 2019-12-30 01:34:22

问题


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.


回答1:


Use the getResponseHeader() method.

Minimal example:

<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>


来源:https://stackoverflow.com/questions/4907876/get-the-response-content-type-header-from-xhr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!