extjs4 global network exception listener

好久不见. 提交于 2019-12-05 20:01:59

This should work:

Ext.override( Ext.form.action.Submit, { 
    handleResponse : function( response ) {

        var form = this.form,
            errorReader = form.errorReader,
            rs, errors, i, len, records;

        if (errorReader) {
             rs = errorReader.read(response);
             success = rs.success;
             // Do something if success is false
        }

        this.callParent ( arguments ); 
    }
});

Have a look at the source code for the exact handleResponse() method from which I copied most of the code above.

Ivan Novakov

IMHO you don't need to override anything. You can place a listener on the Ext.Ajax singleton like it is described here:

Override Ext.data.Connection - Best Practice

Another option is to use the Ext.util.Observable.observe() function as described here:

http://www.sencha.com/forum/showthread.php?172269-Global-connection-handler-for-500-404-403-response-codes

Ext.util.Observable.observe(Ext.data.Connection);

Ext.data.Connection.on('requestexception', function(conn, response, options, eOpts) {
    //...handle it
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!