PDA

View Full Version : how to pass a parameter through ajax



tianhao
15 Aug 2012, 6:31 PM
hi all,
i have finished an ajax grid. it works good. here is the code:
xtype: 'gridpanel',
id: 'mygrid',
......
store: Ext.create('Ext.data.Store',{proxy: {type: 'ajax',url: 'duty.json.ajax.php',reader: {...}}})
this is ok. but when i add a parameter to url of proxy, it doesnt work. i replace url with
url: 'duty.json.ajax.php?id='+Ext.getCmp('id').getValue()
the web console of firefox said
TypeError: Ext.getCmp("id") is undefined
and nothing was displayed.
plz help me.

mixo
15 Aug 2012, 6:53 PM
hello

I guess your problem not in ajax. what you expect to get by Ext.getCmp('id').getValue()?
First step is try manually get this value by typing in console Ext.getCmp('id').getValue().

I think there is bad style use an ID of cmp, if it's possible better access to cmp is call for parent cmp like this


cmp = parent_cmp.down('[name=cmpName]')

tianhao
15 Aug 2012, 9:00 PM
it didnot work
console prompted ok when i run Ext.getCmp('id').getValue(). the result is 4. that is right.
any help will be appreciated.

mixo
15 Aug 2012, 9:14 PM
Strip calculate url and ajax request



myUrl = 'duty.json.ajax.php?id='+Ext.getCmp('id').getValue()
console.log(myUrl);
...
url: myUrl

friend
17 Aug 2012, 5:05 AM
You can also do this:



yourGrid.getStore().load({
params: {
someParam: 'someValue'
}
});