开发者

Get the response Content-Type header from XHR

开发者 https://www.devze.com 2023-02-09 06:08 出处:网络
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.Use the getResponseHeader

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.


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

精彩评论

暂无评论...
验证码 换一张
取 消