Tomas
Tomas

Reputation: 18117

jQuery+AJAX response header

I am trying to read response headers using JQuery and Ajax but not all headers are returned. Only few of them.

$(document).ready(function () {

  $.ajax({
    type: 'POST',
    url:'http://do.convertapi.com/Word2Pdf',
    data: '',
    complete: function(resp){
        alert(resp.getAllResponseHeaders());
         }});

});

Working example: http://jsfiddle.net/tomasr/7jWSv/3/

The server response has CORS header included above, so it should be no problems accessing headers using ajax?

Access-Control-Allow-Origin:*

I would like to read all response headers using ajax, any idea how to do that?

Upvotes: 2

Views: 901

Answers (1)

Tomas
Tomas

Reputation: 18117

The problem solved by adding

Access-Control-Expose-Headers

to the server response and listing all headers like this

Access-Control-Expose-Headers: x-header-1, x-header-2, x-header-3

The response header above let Ajax request to read cross domain headers.

Upvotes: 1

Related Questions