January 8th, 2009 Ext.Ajax Event Handlers
A user presses a button, and it submits an ajax request - once it hits the server, if there is a session timeout, we will set a header noting there is an error. In the requestcomplete event, we want to check for the header, if it exists we want to cancel the original callback, and show a dialog box for login.
So my question is, can we cancel the initial ajax callback?
Ext.Ajax.request = Ext.Ajax.request.createInterceptor(function(...) {
// your code here
});
Ext.Ajax is a singleton that always exists so you can use Function.createSequence() or Function.createInterceptor() to add the functionality you need to its methods or you can replace whole methods with your own ones taking the originals as models.
If the users clicks a button, makes the ajax call, but his session has ended, we could set a header that gets picked up in the 'requestcomplete' event. If the header is present, we cancel the callback, pop up a dialog box, process the login, then send the initial request back through (we will have a cached copy of the original request). This should provide a seamless session structure, and it would be centralized so we don't have to add code to every single ajax call to handle session timeouts, permission problems, etc.
Ext.Ajax.request({
url: '/active/admin/cfc/branchesModel.cfc?method=saveBranch',
success: function(response) {
branchList_store.load();
branchList.reconfigure(branchList_store, branchList_cm);
Ext.MessageBox.alert('Status', 'Your changes were saved successfully.');
},
failure: function(response) {
if(response.getResponseHeader.CustomHeader == "585")
Ext.MessageBox.alert('Status', 'You do not have permission to do this.');
else
Ext.MessageBox.alert('Status', 'There was an unknown error saving your changes.
Please try again.
Detailed Error: ' + response.getResponseHeader.CustomHeaderMessage);
},
headers: {
},
params: {
....
}
})
Ideally, we would like to be able to prevent the 'failure' function from calling, and we'd like to handle the failure from a centralized object.
I see that you're getting your headers and displaying message boxes that is perfectly correct and straightforward.
#If you have any other info about this subject , Please add it free.# |