HTTP प्रतिक्रिया हेडर AJAX में JavaScript में
प्रतिक्रिया हेडर 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 हेडर की सामग्री प्राप्त करें।