0

I have a problem with my app. I have no errors in my code but sometimes I get an error from the extjs library file (ext-all.js) and if I refresh the page it works. The error is shown in IE:

Ext.getCmp(..) is null o not an object / extjs-all.js line 21 char 67494

My Ajax request

Ext.Ajax.request({
url: 'script/request.php?operazione=isadmin',
success: function(response){
    var role = response.responseText;
    switch(role){
        case 'admin':
            Ext.getCmp('gestioneUtenti').show();
            Ext.getCmp('ricercaTarga').show();
            break;
        case 'targhe&offerte':
            Ext.getCmp('ricercaTarga').show();
            break;
        case 'targhe':
            Ext.getCmp('ricercaTarga').show();
            break;
    }
}
});

My code:

// Definisco viewport
Ext.define('Pollini.view.mainView', {
    extend: 'Ext.container.Viewport',

    layout: {
        pack: 'end',
        type: 'hbox',
        align: 'top'
    },

    initComponent: function() {
        var me = this;

        Ext.applyIf(me, {
            items: [
                {
                    xtype: 'button',
                    text: 'Ricerca targa',
                    id: 'ricercaTarga',
                    width: 155,
                    border: 0,
                    height: 155,
                    margins: 20,
                    handler: function(){
                        window.location = "search.php";
                    },
                    hidden: true,
                    iconCls: 'targaBtn'
                },
                /*{
                    xtype: 'button',
                    text: 'Offerte',
                    id: 'offerte',
                    width: 155,
                    height: 155,
                    margins: 20,
                    handler: function(){
                        window.location = "offerte.php";
                    },
                    hidden: true,
                    iconCls: 'offerteBtn'
                },*/
                {
                    xtype: 'button',
                    text: 'Gestione utenti',
                    id: 'gestioneUtenti',
                    width: 155,
                    height: 155,
                    margins: 20,
                    handler: function(){
                        window.location = "users.php";
                    },
                    hidden: true,
                    iconCls: 'utentiBtn'
                },
                {
                    xtype: 'button',
                    text: 'Logout',
                    width: 155,
                    height: 155,
                    margins: 20,
                    handler: function(){
                        Ext.Ajax.request({
                            url: 'script/request.php?operazione=logout',
                            success: function(){
                                window.location = "index.php";
                            }
                        });
                    },
                    iconCls: 'logoutBtn'
                }
            ]
        });
        this.callParent(arguments);
    }
});

Ext.create('Pollini.view.mainView');
4

0 回答 0