Login Register

XHR Not Returning HTTP Redirect Requests

Hi, I am trying to read redirect requests by introspecting HTTP response headers, but I am unable to get access to them. Sometimes Dojo is telling me that a 200 status is returned (IE 7) and other times Dojo simple exits when it calls xhr.open(...) (no error; the Javascript engine simply exits). I saw a post on 302 status codes, but the server is not responding with those according to Dojo.

Essentially, I am using Dojo 1.0.2 and trying to determine if a user is logged out from a JA-SIG CAS server by detecting redirects (or even the Location header from the HTTP response).

Any help is appreciated.

Julian

hrmmm....

I'm not sure that we even get access to a 302 on the script-side of things. Can you verify that you're getting a callback into the handler() function at all? If not, I'm really unsure how we would either detect this or inform you.

--
Project Lead, The Dojo Toolkit
President, The Dojo Foundation

Sorry if I wasn't clear, but

Sorry if I wasn't clear, but I am getting a callback in the error() function and I can get one with the handle() function (both in IE 7). The status code there is 200 for some reason, and my TabContainer is showing a message of "Sorry, an error occurred". Firebug shows the expected headers, and the page goes nowhere since it's an AJAX call. I've tried the following handler in order to get a handle on the Location Header, but it fails:

error: function(response,ioArgs){

alert(ioArgs.xhr.status);
if (ioArgs.xhr && (ioArgs.xhr.status == 301 || ioArgs.xhr.status == 302))

var url = ioArgs.xhr.getResponseHeader('Location');
alert(url);
}

}

I've also tried the above code without detecting for 301 or 302, but that also fails to return the Location header. I pulled this method from the following page:

http://dojotoolkit.org/book/dojo-book-0-9/part-3-programmatic-dijit-and-...

It appears to be a valid approach as well:

http://www.w3schools.com/dom/met_http_getresponseheader.asp

Any input would be greatly appreciated.

Does anyone have any

Does anyone have any suggestions on this? Someone recently told me that DWR supports this via its textHTMLHandler:

http://getahead.org/dwr/other/errors

I imagine if DWR can, Dojo should be able to, but I am skeptical at this point that either can.

Thanks,
Julian

I may not be remembering

I may not be remembering correctly, but I do not think 302/301 gets propagated up through the XHR object the JavaScript callbacks. You can verify though by constructing a test using the browser-native XMLHttpRequest object directly. If you do a test, it would be interesting to hear the results.

I have actually done some

I have actually done some testing of this recently, and I basically found that it is not possible to get access to the redirect status code or the Location header that accompanies the initial redirect response when using XMLHttpRequest. This is because most of the current browser implementations of XMLHttpRequest automatically execute the actual redirect, so by the time you get a callback (and from what I found testing with the raw XMLHttpRequest object, by the time the readyState changes to "receiving") the response will be the location to which you've been redirected (which is why you would be seeing a 200 status code).

There are some nice functional tests here that demonstrate this:
http://www.mnot.net/javascript/xmlhttprequest/

-Jeremy

Jeremy, Thanks for the

Jeremy,

Thanks for the response. This is the understanding I've come to as well. Unfortunately, I do not always get the response of the redirect b/c the source of the redirect is a SSO server on either another protocol (SSL) or another domain name (basically sandboxing prevents the Javascript from getting anything valuable). I'll have to figure out another way of getting this to work. Thanks.