簡體   English   中英

從XHR獲取響應Content-Type標頭

[英]Get the response Content-Type header from XHR

我想看看標題是text / html還是text / xml。 如果它是text / html那么就出現了錯誤,我寧願在繼續之前抓住它。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM