Get the response Content-Type header from XHR

前端 未结 1 1320
挽巷
挽巷 2020-12-29 03:20

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条回答
  • 2020-12-29 03:50

    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 讨论(0)
提交回复
热议问题