0

I am submitting a form via an Ajax call to a 3rd party server. I have to include a return url as hidden data type in the form. Upon submit the 3rd party processes the data and redirects via a 302 response to the url which I specify.

Is there anyway for me to read the header location redirect url, I can see it in the header response in developer tools but can't read the data into a variable as follows:

$.ajax({
      url:'https://3rdparty.com/somescript.php',
      type:'POST',
      data:myVar,
      crossDomain: true,
      success:function(reply){
           alert(reply.getResponseHeader("Location"));
      }

});

Thank you in advace.

Alan.

Alan A
  • 2,557
  • 6
  • 32
  • 54

1 Answers1

1

Change your success function to something like this

success: function(data, status, xhr) {
    alert(xhr.getResponseHeader('Location'));
}

If that does not work, check out this thread

Community
  • 1
  • 1
Rafa Paez
  • 4,820
  • 18
  • 35
  • I changed the success as advised, but the error/failure function always evaluates as true rather than the success function... – Alan A Feb 23 '14 at 15:58
  • It could be different things, I have updated it with a SO thread that is very helpful for your case. – Rafa Paez Feb 23 '14 at 16:07
  • I believe JQuery treats any response not within the 200-299 range counts as a failure. You can use this same function implementation in your `failure` function, or better yet, use `complete` instead. – pieman72 Feb 24 '14 at 04:11