Simple hack to catch redirections after an ajax request. It is not a clean and perfect solution but it should address most cases.

fix #181
This commit is contained in:
Antoine Nguyen
2012-01-10 10:40:22 +01:00
parent baec1f740e
commit ba0ed344c5
16 changed files with 74 additions and 21 deletions
+3
View File
@@ -206,6 +206,9 @@ var AnchorNavigation = new Class({
new Request.JSON({
url: query,
noCache : true,
onComplete: function() {
ajax_login_redirect();
},
onSuccess: function(resp) {
var callback = ($defined(resp.callback)) ? resp.callback : "default";
this.callbacks[callback](resp);
+1 -1
View File
@@ -229,4 +229,4 @@ saveparams = function(id, message) {
}
}).send();
});
};
};
+30
View File
@@ -0,0 +1,30 @@
/*
* Collection of functions that are accessible to every page.
*/
/*
* Simple function that redirect ajax requests to the login page if
* the status code received with a response is equal to 278.
*/
function ajax_login_redirect() {
if (this.status != 278) {
return;
}
var params = "?next=" + window.location.pathname;
window.location.href =
this.xhr.getResponseHeader("Location").replace(/\?.*$/, params);
}
/*
* Simple wrapper around Request.JSON. We just ensure that
* redirections are correctly catched. (on session timeout for
* example)
*/
Request.JSON.mdb = new Class({
Extends: Request.JSON,
options: {
onComplete: ajax_login_redirect
}
});