3

I get a 303 response with a location header, how can I prevent XMLHttpRequest from redirecting?

Below is the code

var xhr = new XMLHttpRequest();

xhr.open('GET', '/api/v1/test' + $(e.target).data('machineimage'));

xhr.onreadystatechange = function () {
    if (xhr.readyState == 4) {
        // here I need to get the `location` header and do something with it
        // xhr.getResponseHeader('location')
        // but before it reaches here, there is a redirect
    }
};

xhr.send();

I observed its the same with jquery as well, is there anyway to bypass this?

Madhusudhan
  • 8,374
  • 12
  • 47
  • 68
  • This isn't possible, I believe, due to security risks. – SReject Nov 16 '12 at 16:23
  • The redirect will be done by the server, so I don't think there is anything you can do about it at that point. – Rory McCrossan Nov 16 '12 at 16:23
  • This isn't possible, for an explantion see [this post](http://stackoverflow.com/questions/3820663/is-it-possible-for-xhr-head-requests-to-not-follow-redirects-301-302) – SReject Nov 16 '12 at 16:24
  • Possible duplicate of [Prevent redirection of Xmlhttprequest](http://stackoverflow.com/questions/228225/prevent-redirection-of-xmlhttprequest) – user Feb 15 '16 at 17:08

0 Answers0