javascriptajaxextjsinterceptorextjs5

How can I intercept Ajax responses in ExtJs?


I'm working on a project with and I need to intercept all ajax responses before they are handled by their respective caller code.

In , for example, I can do:

axios.interceptors.response.use(
    function (response) {
        // handle response
        return response;
    }, function (error) {

});

How can I do that in extjs ? The docs for Ext.Ajax seem to provide only events for requests.


I'd prefer not installing any additional plug-in / dependency


Solution

  • The docs I have linked show the event requestcomplete, which is fired when a response comes back from the server.

    I wrongly assumed it was fired right after the request was sent.


    So, listening to requestcomplete is the right way to go.

    You can catch successful and unsuccessful responses with the following code:

    Ext.Ajax.on('requestcomplete', function ( conn, response, options ) {
    
    });
    
    Ext.Ajax.on('requestexception', function ( conn, response, options ) {
    
    });