Redirecting an Ajax request

When an error occurs during handling a request, I redirect to a special
controller for error messages. For XML HTTP request I noticed that
Firefox (1.0.7) does not set the X-Requested-With header to
XMLHttpRequest on the second, redirected request. Konqueror (3.5.2),
the only other browser I’ve checked, does add the header as expected.

I’m working around this by adding an additional param to the redirect_to
that indicates that it is meant to be handled as an XHR even though
request.xhr? is not true.

Now I’m wondering whether there’s anything wrong with redirecting XHRs
or if it’s just a bug in that version of Firefox.

Michael


Michael S.
mailto:[email protected]
http://www.schuerig.de/michael/

Michael S. wrote:

When an error occurs during handling a request, I redirect to a special
controller for error messages. For XML HTTP request I noticed that
Firefox (1.0.7) does not set the X-Requested-With header to
XMLHttpRequest on the second, redirected request. Konqueror (3.5.2),
the only other browser I’ve checked, does add the header as expected.

I’m working around this by adding an additional param to the redirect_to
that indicates that it is meant to be handled as an XHR even though
request.xhr? is not true.

Now I’m wondering whether there’s anything wrong with redirecting XHRs
or if it’s just a bug in that version of Firefox.

Michael


Michael S.
mailto:[email protected]
http://www.schuerig.de/michael/

Instead of doing a hard redirect just redirect via rjs

def foo
raise ‘big nasty error!’
rescue
render(:update) { |page| page.redirect_to error_page_url }
end

Or embed that rescue in a respond_to block to support non-js as well.