问题描述
未捕获TypeError:无法调用未定义的方法request
我的Javascript在下面。任何帮助将不胜感激!
myJsonStore = {
store1:new Ext.data.JsonStore({
root:'rootstore1',
fields:['UserID','UserName']
})
};
// ------我的面板------
项目:[{
xtype:'combo',
id:' ',
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);
通常,当错误为不能调用未定义的方法'X'
,这意味着你尝试调用的任何对象都不存在 X
/ p>
在你的情况下,看起来好像 Ext.Ajax
是未定义的。解决这个问题的最简单方法有两个简单的步骤:
- 确保您已经包含了创建 Ext.Ajax的。如果您使用
ext-all.js
文件,那么您不必担心这一点。 -
确保您的代码都不执行,直到浏览器准备就绪。最好的方式是将所有的代码都包含在一个
Ext.onReady()Ext.onReady(function(){//你的代码到这里});
您可以在。
In my javascript code, I keep getting the following error:
Uncaught TypeError: Cannot call method 'request' of undefined
My Javascript is below. Any assistance would be greatly appreciated!
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);
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.
In your case, it appears as though Ext.Ajax
is undefined. The easiest way to resolve this involves two simple steps:
- 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 });
You can see more examples of this at the ExtJS Examples page.
这篇关于未捕获TypeError:无法调用未定义的方法“请求”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!