Since it is clear that it’s not possible to detect an HTTP Redirect at Javascript level, the job should be done at server side. II The solution A Spring Security 1) Algorithm My opinion is that all these solutions are not satisfactory because they require many hacks and tamper with the response string/content itself. Many contributors suggest to add a special attribute in the JSON response to indicates a redirect or to add a special Javascript callback to parse the response string searching for a DOM element that characterizes the login page and so on. This issue has been widely debated on Stackoverflow at this thead. What happens it that the Ajax layer receives an HTTP 200 code after the redirection. According to the W3C specs, the redirection is taken care at browser level and should be transparent for the user (so transparent for the XMLHttpRequest protocol too). However, at the XMLHttpRequest level, it is not possible to detect this redirection. ![]() The same mechanism applies if the request is Ajax-based. If your resources is protected by a security framework any un-authenticated request will be rejected and the framework redirects you to a login page. The underlying implementation relies on Ajax calls to achieve content lazy loading. The corner-stone of mobile architecture are RESTfull webservices. Many companies provide a mobile interface of their traditional desktop website to address a larger audience. Nowadays mobile development is getting more and more important for the business. Please note that a demo application for this article can be found on GitHub Įdit: the implementation has been changed to simplify Ajax request detection thanks to Marty Jones suggestions. For those who don’t use Spring Security I’ll show another approach with servlet filter. In this article we’ll see a solution based on Spring Security filter. If you’re not familiar yet with Spring Security, you can check my previous articles on this framework. Recently when developing the Tatami application for the Twitter-like contest, I faced an annoying issue: how to detect an user session timeout when an Ajax request is triggered from the browser ?
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |