views:

43

answers:

2

In my application, I'm loading some table using AJAX. But when user's session times out it gives me login page as response that gets loaded in table area.

I would like to redirect to login page may be in javascript when session timeout occurs during AJAX call.

+1  A: 

When rendering the login page you could append a custom HTTP header to the response: X-LOGIN-PAGE: True. Then perform your AJAX call and check for the presence of this custom header in the success callback. Act accordingly if present.

Darin Dimitrov
In that case I need to check this in each AJAX call on all pages.
Chinmayee
If you are using jquery you could setup global ajax options: [jquery.ajaxSetup](http://api.jquery.com/jQuery.ajaxSetup/) and perform the redirect in the `complete` callback without modifying your existing AJAX calls. If you are not using jQuery, depending on how you are performing your AJAX calls there might or might not be solutions.
Darin Dimitrov
A: 

You can check for the authentication in the method being called by the AJAX call and if not found can just return a flag. In the AJAX handler in the client page, you can detect and redirect to the login page.

Kangkan