• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session Timeout on Ajax Calls

 
Mark Reyes
Ranch Hand
Posts: 426
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 426
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic