I am making ajax requests for cross domains with an html data type. They work fine as I turn on
Access-Control-Allow-Origin
in the server response. The problem is that I need to get specific headers from the server response and no matter what I do, the response headers, except for the "content type", return null.
jQuery fulfills the request, receives the response, including the headers (I see it from the traffic), but it does not parse it.
I tried using
crossDomain: true
It did not help. Here is an example response from the server.
Access-Control-Allow-Origin:* Cache-Control:private Content-Encoding:gzip Content-Length:514 Content-Type:text/html; charset=utf-8 X-MYRESPONSEHEADER:1
If the requesting and responding document are on the same server
success: function (data, status, xhr) { totalRows = xhr.getResponseHeader("X-MYRESPONSEHEADER");
works great. I also tried assigning a variable of type $ .ajax to a variable
var jQxhr = $.ajax(.....
I do not understand why it will not understand, since jQuery really makes a request and gets a response
Any ideas? Did I miss something?
Update or comment on the dragon
Headers sent on request
HTTP/1.1 200 OK Cache-Control: private Content-Type: text/html; charset=utf-8 Content-Encoding: gzip Vary: Accept-Encoding Server: Microsoft-IIS/7.5 Access-Control-Allow-Origin: * Access-Control-Allow-Headers: X-MYRESPONSEHEADER Access-Control-Allow-Methods: POST Access-Control-Allow-Methods: GET X-MYRESPONSEHEADER: 24 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Date: Wed, 29 Feb 2012 11:34:21 GMT
Content-Length: 514
jquery ajax cross-domain
nLL
source share