跳到主要内容

getResponseHeader

2024年04月17日
柏拉文
越努力,越幸运

ajax.getResponseHeader() 返回包含指定响应头文本的字符串。

语法

const ajax = new XMLHttpRequest();
ajax.open("get","htt://localhost:4000/api",true);
ajax.readystatechange = function(){
if(ajax.readyState === 4 && [200,304].includes(ajax.status)){
const contentType=client.getResponseHeader("Content-Type");
if(contentType != my_expected_type) { // 如果这不是你的预期值
client.abort(); // 终止连接
}
}
};
ajax.send();