views:

20

answers:

3

On one of my pages I have a div that uses ajax to load content asyncrohnously. When a session expires the user is supposed to be redirected back to the loggin screen. However, when the session expires and the ajax call is triggered the login page gets put inside the div. What I want is for the user to be redirected back to the login screen.

A: 

Send a notification back to the JavaScript that the session is no longer valid. When the JavaScript gets the appropriate error, have it window.location = http://example.com/.

jsumners
A: 

One way of solving this is to add a text to uniquely identify the login page and use it in AJAX call back to redirect to a login page again. Here is a sample code using jQuery global callbacks....

$(document).bind("ajaxComplete", function(event, response, ajaxOptions) {
    if (response.status == 200 && response.responseText.match(/LOGIN_PAGE_UNIQUE_KEY/)) {
        self.location = "/web/login?timeout=1";
        return false;
    }

});
Teja Kantamneni
Thank u for u r reply.It is working fine
vishnu
Glad I can help. If you like the answer and it solved your problem, accept it by clicking on the tick mark. This will help other people to know which may be best solution for their problem
Teja Kantamneni
A: 

I think that extension headers is the key, the login page could send additional header to be captured by the xmlhttprequest handler.

Or in a more lazy and unreliable approach, use a javascript on the login page, if the location of the current page is not the login one, then use javascript to redirect (it depend on javascript but as you are making xhr request).

dvhh