I have an application in which most requests are sent through AJAX, although some of them are sent through "regular" HTTP requests. If the request is sent and the user session timeout, the following JSON is returned:
{"authentication":"required"}
The JavaScript function that sends all AJAX requests processes this response by displaying a pop-up message and redirecting the user back to the login page.
However, when a non-AJAX request receives this response, JSON is simply displayed in the browser because the response is processed directly by the browser (i.e. the above JavaScript function is disabled). Obviously, this is not ideal, and I would like non-AJAX requests to receive this answer in order to behave the same as AJAX requests. To achieve this, I can think of two options:
Go through the app and convert all requests to AJAX requests. This will work, but can take a long time!
The JSON shown above is generated by a very simple JSP. I am wondering if it is possible to add a JavaScript event handler to this JSP that runs just before the content is displayed in the browser? I assume this will never be called for AJAX requests? This handler may invoke other JavaScript code that displays a popup and redirects.
If anyone knows how exactly I can implement the handler that I described in (2), or has any other potential solutions, I would be very grateful if they would pass them on.
Cheers, Don
Dónal source
share