aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Session Timeout on Ajax Calls Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Session Timeout on Ajax Calls" Watch "Session Timeout on Ajax Calls" New topic
Author

Session Timeout on Ajax Calls

Mark Reyes
Ranch Hand

Joined: Jul 09, 2007
Posts: 426
Hi,

I configure an interceptor/filter in my spring mvc apps that will redirect my user to the Login Page if their session is already expired.

Now, I used jquery ajax in getting some of the data. I also configure a global error handler
should there be a problem.




My problem here is that, I see in my firebug that there is a 302 HTTP status but what happens is that, my Login Page gets appended into my error content.

I checked the exception in the ajaxerror handler and it says "invalid json"

What I want is that if session already expired then user gets redirected to the login page for all ajax calls.

I am not sure how to check for session timeout when using ajax calls. Can somebody give me advice on this?

Thanks.


Sean Clark ---> I love this place!!!
Me ------> I definitely love this place!!!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Personally, I'd say it's risky to attach an Ajax error handler *after* you've made an Ajax request.

If you need to handle a specific response code then you should code a handler just for that error code; there are a variety of ways to do that.
Mark Reyes
Ranch Hand

Joined: Jul 09, 2007
Posts: 426
Hi,

Personally, I'd say it's risky to attach an Ajax error handler *after* you've made an Ajax request.


I rearrange my code and place my ajax error callback above the document ready function. Is this the correct way of having a global
error callback on ajax request? Thanks for your thoughts..



I added also below code, to trap the 302 HTTP response code but I think it's not working though.
I always get an xhr status of 200.



But I see in my firebug that I get a 302 response but I think my firefox browser is handling this on its own. In the end, my login page gets appended into my
errorcontent div and I see an invalid json on the exception.

If you need to handle a specific response code then you should code a handler just for that error code; there are a variety of ways to do that.

Can you give me an idea please on how to properly trap the HTTP response of 302?

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Session Timeout on Ajax Calls