2
  $.ajax({
                async:false,
                type: 'POST',
                url: itemURL,
                success: function(data,status,jqXHR) {
                    responseObj  = data;
                    console.log('success function resp');
                    console.log(jqXHR.getAllResponseHeaders());
                },
                error: function(data){
                    responseObj = data;
                },
                data:item,
                dataType: "json",

    });

Here's my code; i am unable to print response headers; am i missing anything? all that prints out is empty string.

Tried using getResponseHeader("Location"), that's not working either; I am trying to get "Location" header that's being returned for the AJAX call.

However firbeug shows all response headers including "Location" which I am after.

I am using Jquery 1.7.1

Satish
  • 6,457
  • 8
  • 43
  • 63
  • 1
    Redirects are followed and the final response does not have a location header at all. – ThiefMaster Jan 11 '12 at 17:10
  • The datatype might be causing the issue, see here: http://stackoverflow.com/questions/5614735/jqxhr-getallresponseheaders-wont-return-all-headers – Jon Jan 11 '12 at 17:16
  • @Jon dataType is not the issue; tried json, application/json. still the problem remains. I guess it's something to do with "Location" header – Satish Jan 11 '12 at 18:48
  • Satish, you might want to address @ThiefMaster 's comment... Is this a page that is submitting a form? – blong Jan 24 '12 at 04:44
  • @ThiefMaster I think the transparent redirect is the issue here: Found another question about the same: http://stackoverflow.com/questions/228225/prevent-redirection-of-xmlhttprequest – Satish Jan 25 '12 at 19:01

1 Answers1

2

I worked with @Satish in helping to answer this question. This was basically a CORS issue, but, it turns out there were two issues involved here:

1) The server needed to add 'Location' to the Access-Control-Expose-Header response header, this allows conforming XHR Level-2 clients to see the extra header.

2) WebKit clients had a bug where they would ignore the Access-Control-Expose-Header when returning headers for an XHR response. This was fixed in WebKit recently https://bugs.webkit.org/show_bug.cgi?id=76419, and we verified that it's now working in Safari based on that WebKit.

Just to add some background, the request was POSTing to a REST service to create an object. The server response had a status of 201 and stored the location of the new resource in the 'Location' header. As this was a CORS request, the XHR was stripping the 'Location' header. Adding the header and upgrading to a version of WebKit with the fix corrected this issue.

Brian
  • 56
  • 1