I’m trying to develop a web application that makes use of AJAX, but also
if a user has no (or doesn’t want to use) JS. For normal requests, this
pretty easy. Almost every action ends with
render blahblah, :layout => !request.xhr?
This way, I can use the same action to render a full page (with layout)
well as rendering an AJAX request (only the div, no layout)
The problem occurs when doing a redirect_to in an AJAX request (e.g. if
post request was successful and the user is redirected to the list
The AJAX request is properly redirected and the browser requests the new
action… But the new action doesn’t recognize the request as AJAX
(request.xhr? returns false), so that (in my case) it renders the full
where it should only render a single div.
Is this a bug or is the behaviour of request.xhr? undetermined after a
redirect? Could this be browser-specific? (I’m using FF 1.5 for
What would be the proper way to handle this case?
PS: Of course I could use the flash to set a flag that remembers a
AJAX call - but that would just be a workaround :-/