I have clients that issue AJAX calls. These calls reference URLs that are protected by Spring Security on the sever side. If the user's session has timed out, I have a login form popup in a lightbox. After the user has successfully logged in, I would like the client to re-execute AJAX call.
Here's an example of the client side code that makes an AJAX call:
function handleSearchClick(evt) {
var setupOptions = {
success: loadSearch,
type: "POST",
dataType: "json",
url: "../search.ajax",
error: handleError, // how can I pass callback info i.e. I want to be able to execute $("#searchForm").ajaxSubmit(setupOptions); from handleError?
timeout: 50000
};
$("#searchForm").ajaxSubmit(setupOptions);
}
When the authentication fails, the server returns a 401 which results in the client calling handleError. Is it possible to pass a callback function to handleError? I would want the callback to re-execute
$("#searchForm").ajaxSubmit(setupOptions);
I have seen solutions to this problem where the server returns a success response on AJAX calls that have a session timed out. Then, the success function looks for something in the response to know the session timeout. The client then stores a callback function there. I prefer though to handle this in the error function.