L
L
LB7772015-04-22 16:13:05
JavaScript
LB777, 2015-04-22 16:13:05

How to get header value in AJAX request?

Connecting to the server via https.
It gives me headers:
Content-Type: application/json; charset=utf-8
and
X-Powered-By: ASP.NET
Which the fidler confirms.
Ajax request via XMLHttpRequest

var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", url, true);
xmlhttp.onreadystatechange = function(){
 if (xmlhttp.readyState === 4) {
  if(this.status >= 200 && this.status < 400) {
   var contentType = xmlhttp.getResponseHeader('Content-Type');
   var poweredBy = xmlhttp.getResponseHeader('X-Powered-By');
  }
 }
};
xmlhttp.send(null);


But for some reason, I'm only getting the value from the Content-Type header, and I'm getting null from the X-Powered-By header.
Why is that? And how to make it so that through XMLHttpRequest to get the value of the X-Powered-By header?
==============================
As it turned out later, the problem lies in the cross-domain request. On the server, all headers seem to be allowed. Is there anything else that needs to be specified?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
LB777, 2015-04-23
@LB777

Helped Access-Control-Expose-Headers
Ie . registered on the server
And everything worked

I
Ilya Shatokhin, 2015-04-22
@iShatokhin

Should work. Try looking through xmlhttp.getAllResponseHeaders().

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question