mardi 6 mai 2014

Returning data from Ajax call in Ext.onReady

I have an Ext JS app and I want to check on the backend if the session is invalid every time a user clicks on a link within the app. These two Ajax calls are both in Ext.onReady, I would like to clean up this code but I need to check for timeout every click, the second Ajax call is only called upon logging in if it were by itself. This is in my app.js also.

Code:



Ext.Ajax.on('requestcomplete', function(conn, response, options, options) {
if(!isSessionValid()) {
window.location.href = '?login_status=timeout';
}
});

function
isSessionValid() {
Ext.Ajax.request({
url: contextRoot + '/isSessionValid.htm?alt=json',
method: 'get',
success: function(response, options) {
console.log(response);
var isValid;
var o = Ext.decode(response.responseText);
(o != loggedInUser.username) ? isValid = false : isValid = true;
return isValid;
},
failure: function(response, options) {
//console.log(response);
}
});
}

Obviously isSessionValid will return undefined.. is there a workaround to get the data I need and not have my ajax call continuously calling?


Aucun commentaire:

Enregistrer un commentaire