January 8th, 2009 Ext.Ajax Event Handlers

  • Is it possible from the requestcomplete event to cancel the ajax callback function? Here's the scenario:

    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?


  • No, you would do something like this:


    Ext.Ajax.request = Ext.Ajax.request.createInterceptor(function(...) {
    // your code here
    });


  • Can you post some code that would show how do you make the request?


  • That is beautiful. Outstanding suggestion. Thanks Saki.


  • I just found these - please disregard.


  • Now I get it, thanks for explanation.

    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.


  • createInterceptor returns an interceptor function. Do I need to call this function instead of the Ajax.request function or does calling Ajax.request.createInterceptor() inject the interceptor into every Ajax.request function call?


  • I am hoping to create a centralized security object. We have quite a few ajax calls, and it would be nice to intercept all of the 'end' requests, and if there are errors or failures deal with it in the centralized object. An example:

    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.


  • Where can I find more information on how to use createSequence and createInterceptor?


  • Thanks for the prompt reply. Here is a code snippet:


    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'm trying to figure out what could be a task that cannot be handled from within of failure function.

    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.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about Ext.Ajax Event Handlers , Please add it free.