JavaScript에서 AJAX를 통한 HTTP 응답 헤더
응답 헤더는 response 객체의
headers 속성에 저장됩니다.
어떤 헤더를 가져와 보겠습니다:
button.addEventListener('click', function() {
fetch('/ajax.html').then(response => {
console.log(response.headers.get('Content-Type'));
});
});
이제 반복문으로 모든 헤더를 순회해 보겠습니다:
button.addEventListener('click', function() {
fetch('/ajax.html').then(response => {
for (let [key, value] of response.headers) {
console.log(key, value);
}
});
});
Content-Language 헤더의
내용을 가져오세요.
Content-Length 헤더의
내용을 가져오세요.