override Ajax.js with listener for requestexception not working

强颜欢笑 提交于 2020-01-16 04:24:29

问题


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
            });
            }
        }
    }
});

回答1:


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
        }
    });
});


来源:https://stackoverflow.com/questions/26972640/override-ajax-js-with-listener-for-requestexception-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!