I'm trying to solve the problem of session timeouts when doing ajaxy things. I am using jQuery, and have a function set up for when there is an ajax error. If it is a 401 error, I want to basically pause everything, let them log in with a popup window, and then resume everything. I'm not entirely sure, but callbacks and closures seem like words that might help this work, if I knew more about them, and if it is possible to keep track of an ajax request and retry it on some event called later.
So if they are doing the ajax call like this
data = {
input: value
};
if ($j.statusXHR) {
$j.statusXHR.abort();
}
$j.statusXHR = $j.ajax({
url: url,
data: data,
type: "POST",
success: function (data) {
div.html(data);
},
error: function (request, textStatus, error) {
handleErrors(request, textStatus, error, $j.statusXHR, contentDiv, data);
}
});
And if they aren't logged in, it goes down into this function, which displays a button to login, which opens a popup window for the login page (can't do this with ajax since openid is on another domain).
function handleErrors(request, textStatus, error, xhr, elem, data) {
if (request.status === 401) {
// not logged in
url = "/login/ajaxExpired";
if (xhr) {
xhr.abort();
}
$j.ajax({
url: url,
success: function (data) {
elem.html(html);
}
});
}
}
The return_to page of the openid part should detect whether the login was successful, based on the returned parameters, and close the popup window and initiate the original ajax request. This is the part that I'm wondering about. Is it possible?