Using jQuery (latest version), IBM WebSphere 6.1 Server, Java JDK 1.5
You have some pickle for AJAX calls. All of my AJAX calls relate to URLs that are part of my web.xml security restriction that requires authentication. Authentication is a standard form of j_security, so with each request for a secure / secure URL, the container (WebSphere) will intercept this call and see if authentication is good, and if authentication does not work, it will automatically be redirected to the login page. Pretty simple / standard and expected, I think.
Take a look at the following code. Regardless of the clientβs authentication status (authenticated, not authenticated, timeout), a GET call (or message, does not matter) to this URL ALWAYS returns 200. So there really is no easy way to find out if we were redirected or not, if we do not evaluate the data returned by the server.
Perhaps I missed something? This seems really confusing. The only reliable way I found to see if we were redirected to j_security is to return data from the server and do a dom search for the j_password field. But that seems really inefficient, as that is what I have to do for every AJAX call in my application. Some of our AJAX calls relate to URLs that return JSON and some that return HTML.
$.ajax({
type: 'GET',
url: '<c:url value="/secure/supersecretthingy.html"/>',
dataType: 'html',
data:{
requestDate: requestDate
},
beforeSend: function(request) {
},
complete: function(request) {
},
success: function(data, textStatus, response) {
var ll = $('<div id="#wee" class=""></div>').html(data).find("#j_password").length;
$("#wee").remove();
if ( ll != 0) {
window.location = '<c:url value="${GLOBAL_AJAX_TIMEOUT_PAGE}" />';
} else {
dialogDiv.html(data);
}
},
error: function(xhr, textStatus, errorThrown) {
}
});