gpt4 book ai didi

javascript - 未捕获的类型错误 : Cannot call method 'request' of undefined

转载 作者:数据小太阳 更新时间:2023-10-29 05:41:53 25 4
gpt4 key购买 nike

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

未捕获的类型错误:无法调用未定义的方法“请求”

我的 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);

最佳答案

通常,当错误的形式为 Cannot call method 'X' of undefined 时,这意味着您尝试从中调用 X 的任何对象都不存在.

在您的例子中,看起来好像 Ext.Ajax 是未定义的。解决此问题的最简单方法包括两个简单的步骤:

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

    Ext.onReady( function() { //your code goes here });

您可以在 ExtJS Examples page 看到更多这方面的例子.

关于javascript - 未捕获的类型错误 : Cannot call method 'request' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5776847/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com