I have a JRuby on Rails application using a lot of Ajax GET calls. The result is inserted in the HTML page. If the session times out, the resulting html is the login page. This login page is then inserted into the current HTML page. Instead, a redirect to the login page should happen…
How is this problem generally tackled?
You can’t catch the 302 because browsers hide that from you – your ajax request just sees the final request.
When this has been an issue I usually change my login code such that if access is attempted to a restricted page by a non logged in user, and the request is an ajax request I render a special status code (usually a 4xx code). Check for that status code in your ajax request handlers (depending on jour ajax library, you can usually set up a global handler) and if you see it, redirect the user to the login page.