Extract HTTP headers from HTTP-300 responses using Ajax

I execute an Ajax request to a server that accepts cross-domain requests, but for which I do not control the server code. My desire is to extract the HTTP Link header from the response. As an example:

$.ajax({
 url: theURL
}).done(function(data,textStatus,xhr){});

accesses the server, which responds with the following (as you can see when the URL is requested using curl):

HTTP/1.1 302 Found
Link: <http://thedataIwant.com>;rel="foo"
Location: http://someothersite.com

The browser follows the 3XX HTTP code, and I get the contents of the HTTP headers from http://someothersite.com in the handler done(); however, I would like to first extract the contents of the Link header for the initial HTTP response with 3XX code.

How can I extract the contents of an HTTP Link header from an HTTP response with a 3XX status code?

+4
1

. , . , ( jQuery Ajax ), 301 , 200 302. . ajax, , Link, ajax, MyRedirectLocationHeader: http://someothersite.com.

:

$.ajax({
    url: theURL,
    success: function(response, status, xhr) {
        var link = xhr.getResponseHeader('Link');
        if(link != null) {
            // my second ajax request to the link in the MyRedirectLocationHeader
        }
    }
});

, , , . proxy script/service PHP, Java , Link Location JSON XML. javascript someothersite.com

, , jQuery ajax documentation 3xx ( statusCode), , , .

+3

All Articles