ajax redirect dillema, how to get redirect URL OR how to set properties for redirect request
- by Anthony
First, I'm working in Google Chrome, if that helps. Here is the behavior:
I send an xhr request via jquery to a remote site (this is a chrome Extension, and I've set all of the cross-site settings...):
$.ajax({
type: "POST",
contentType : "text/xml",
url: some_url,
data: some_xml,
username: user,
password: pass,
success: function(data,status,xhr){
alert(data);
},
error: function(xhr, status, error){
alert(xhr.status);
}
});
The URL that is being set returns a 302 (this is expected), and Chrome follows the redirect (also expected).
The new URL returns a prompt for credentials, which are not being pulled from the original request, so Chrome shows a login dialog. If I put in the original credentials, I get back a response about invalid request sent (it's a valid HTTP request -- 200 -- the remote server just doesn't like one of the headers).
When viewing the developer window in Chrome, there are two requests sent. The first is to the original URL with all settings set in the ajax request. The second is to the redirect URL, with a method of "GET", nothing from the "POST" field, and no credentials.
I am at a loss as to what I can do. I either need to:
Get the redirect URL so I can send a second request (xhr.getResponseHeader("Location") does NOT work),
Have the new redirect request preserver the settings from the original request, or
Get the final URL that the error came from so I can send another request.
Ideally I don't want the user to have to put in their credentials a second time in this dialog box, but I'll take what I can get if I can just get the final URL.