未捕获的TypeError:无法调用未定义的方法'request'

use*_*045 5 javascript json extjs

在我的JavaScript代码中,我不断收到以下错误:

Uncaught TypeError: Cannot call method 'request' of undefined

我的Javascript在下面.任何帮助将不胜感激!

myJsonStore = {
    store1: new Ext.data.JsonStore({
        root: 'rootstore1',
        fields: ['UserID', 'UserName']
    })
};  

//------My panel------
items: [{                           
    xtype: 'combo',                          
    id: 'UName',                            
    fieldLabel: 'User',
    emptyText: 'All',                            
    store: myJsonStore.store1,                          
    displayField: 'UserName',                            
    valueField: 'UserID'                               
}] 

//--------------------

Ext.Ajax.request({                             
    url: "rPages/rLogMatchOdds.aspx",                            
    params: {                               
        m: 'init'                            
    },                                
    success: function(response) {     
        var data = Ext.decode(response.responseText);
        myJsonStore.store1.loadData(data);
    }
});

Ext.getCmp('UName').store.on('load', function(my, rec) {
    Ext.getCmp('UName').setValue(rec[0].get('UserName'));                         
}, this);
Run Code Online (Sandbox Code Playgroud)

NT3*_*3RP 17

通常,当错误是表单时Cannot call method 'X' of undefined,意味着您尝试调用的任何对象X都不存在.

在您的情况下,它似乎Ext.Ajax是未定义的.解决此问题的最简单方法包括两个简单的步骤:

  • 确保您已包含创建的javascript文件Ext.Ajax.如果您正在使用该ext-all.js文件,那么您不必担心这个问题.
  • 确保在浏览器准备好之前不会执行任何代码.执行此操作的最佳方法是将所有代码包装在 Ext.onReady()调用中.我在下面提供了一个例子.

    Ext.onReady( function() { //your code goes here });
    
    Run Code Online (Sandbox Code Playgroud)

您可以在ExtJS Examples页面上看到更多这方面的示例.

  • 如果你弄清楚了,你能否发布你如何解决它以帮助其他可能跟随的人? (20认同)