-1

i want to read specific headers for current html page, this code below read all headers, how i can read a specific header having the tag?

   var req = new XMLHttpRequest();
   req.open('GET', document.location, false);
   req.send(null);
   var headers = req.getAllResponseHeaders().toLowerCase();
   alert(headers);

This code return this result: date: mon, 11 may... last-modified: mon, 11 m... accept range: bytes ...etc..

is there a method to read a specific field in headers ?

Malo
  • 1,232
  • 2
  • 17
  • 28

1 Answers1

1

try to use getResponseHeader instead of getAllResponseHeaders to extract a specific header :

var header = req.getResponseHeader('last-modified');
Kalmani
  • 51
  • 3
  • thx its working, but if the page looks like index.html?name=malo how can i read name? var header = req.getResponseHeader('name'); i tried this but not working – Malo May 11 '15 at 10:14
  • GET arguments are not part of the headers. You should take a look in here : http://stackoverflow.com/questions/979975/how-to-get-the-value-from-the-url-parameter and use his function QueryString to extract them as an Object :) – Kalmani May 11 '15 at 10:24