简体   繁体   中英

override Ajax.js with listener for requestexception not working

This is included in a requires statement in the main app. It loads Ajax then dies. I'm using Extjs 5. The code is in an overrides folder under ui/. It can't seem to find the code in a folder at the same level as app.

Ext.define('Ext.overrides.Ajax', {
    override : 'Ext.data.Connection',
    listeners : {
        requestexception : function(response) {

        var error = response.status + ' - ' + response.statusText;
        // if response status is 202 (Accepted), should
        // have warning message
        if (response.status == 202) {
            Ext.Msg.show({
                title : 'REST Warning message',
                msg : 'Ajax Request Exception! ' + error,
                cls : 'msg-wrap',
                buttons : Ext.Msg.OK,
                icon : Ext.Msg.WARNING
            });
        }

        if (response.status > 400) {
            var errorData = Ext.JSON.decode(response.responseText);

            Ext.Msg.show({
                title : 'REST Error message',
                msg : 'Ajax Request Exception! ' + errorData,
                cls : 'msg-wrap',
                buttons : Ext.Msg.OK,
                icon : Ext.Msg.ERROR
            });
            }
        }
    }
});

I had a similar issue. In ExtJS 4, I had a Ext.Ajax override configured just like yours.

To get it to work with ExtJS 5, I read http://www.sencha.com/blog/top-support-tips-october-2014 and successfully changed my override structure to the following:

 Ext.define('Ext.override.AjaxOverride', {
    override: 'Ext.Ajax'
    // omitted overridden properties...

}, function() {
    var me = this;

    me.setExtraParams({
        foo: "bar" 
    });

    me.setUrl('MyUrl');
    me.setTimeout(600000);

    me.on({
        scope: me,
        requestexception: function(conn, response, opts) {
            // my exception handling
        }
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM