Javascript 未捕获的类型错误:无法调用未定义的方法“请求”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5776847/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Uncaught TypeError: Cannot call method 'request' of undefined
提问by user715045
In my javascript code, I keep getting the following error:
在我的 javascript 代码中,我不断收到以下错误:
Uncaught TypeError: Cannot call method 'request' of undefined
Uncaught TypeError: Cannot call method 'request' of undefined
My Javascript is below. Any assistance would be greatly appreciated!
我的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);
回答by NT3RP
Usually, when the error is of the form Cannot call method 'X' of undefined
, it means that whatever object you are attempting to call X
from does not exist.
通常,当错误的形式为 时Cannot call method 'X' of undefined
,这意味着您尝试调用的任何对象X
都不存在。
In your case, it appears as though Ext.Ajax
is undefined. The easiest way to resolve this involves two simple steps:
在您的情况下,它似乎Ext.Ajax
未定义。解决此问题的最简单方法包括两个简单的步骤:
- Make sure that you've included the javascript file that creates
Ext.Ajax
. If you're using theext-all.js
file, then you shouldn't have to worry about this. Make sure that none of your code executes until the browser is ready. The best way to do this is to wrap all of your code within a
Ext.onReady()
call. I've provided an example below.Ext.onReady( function() { //your code goes here });
- 确保您已包含创建
Ext.Ajax
. 如果您正在使用该ext-all.js
文件,那么您不必担心这一点。 确保在浏览器准备就绪之前,您的任何代码都不会执行。最好的方法是将所有代码封装在一个
Ext.onReady()
调用中。我在下面提供了一个例子。Ext.onReady( function() { //your code goes here });
You can see more examples of this at the ExtJS Examples page.
您可以在ExtJS 示例页面查看更多示例。
回答by Alvinator
Got bitten by this problem too.
也被这个问题咬了。
The solution is for you to call Ext.require('Ext.Ajax')
before Ext.onReady
like so:
该解决方案是给你打电话Ext.require('Ext.Ajax')
之前Ext.onReady
,像这样:
Ext.require('Ext.Ajax');
Ext.onReady(function() {
Ext.Ajax.request({
// your code here...
});