-
2 May 2012 10:52 AM #1
Unanswered: JsonP request
Unanswered: JsonP request
Hi all,
I want to make a json request(calling a web service).
I need to pass three parameters (url,userid,accesskey) to the .php file for validation purpose.
I tried two ways, but both not working for me. The .php file state the parameters didnt passed
Here's my code:
this is my first way:
Code:xtype: 'button', text: 'Accounts', handler: function() { Ext.data.JsonP.request({ url: 'php/vtiger_account.php', callbackKey: 'callback', params: { url: url, userid: userid, accesskey: accesskey }, success: function(result) { Ext.getCmp('usermenu').push({ title: 'Accounts', xtype: 'list', store: 'Accountstore', itemTpl: '<div>{account_no}</div>{accountname}', }); } }); }
this is my 2nd way:
Code:Ext.define('accountmodel', { extend: 'Ext.data.Model', config: { fields: ['accountname','account_no','accounttype','phone'] } }); //Store var accountstore = Ext.create('Ext.data.Store', { //create data store 'Login1model.js' storeId:'Accountstore', model: 'accountmodel', proxy:{ type:'jsonp', url:'php/vtiger_account.php', callbackKey:'callback', extraParams:{ url: url, userid: userid, accesskey: accesskey } reader:{ type:'json' }, } }); Ext.define('SCM.view.Account', { extend: 'Ext.navigation.View', xtype: 'accountlist', id: 'accountlist', fullscreen: true, config:{ navigationBar: false, items:[ { title: 'Accounts', xtype: 'list', store: 'Accountstore', itemTpl: '<div>{account_no}</div>{accountname}', } ] }
BOTH is not working for me. Any help will be appreciated. Thank you.Last edited by mitchellsimoens; 4 May 2012 at 5:46 AM. Reason: added [CODE] tags
-
4 May 2012 5:47 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,107
- Vote Rating
- 453
- Answers
- 3155
Have you looked at the request? Are the params there?
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
10 Dec 2012 6:51 AM #3
If extraParams contains vars, they will not submitted to server. With static content its fine. also json-proxy works. it took my hours to recognize that. I was believing my var is not initialize at right time, but i think it is a bug!
-
10 Dec 2012 7:47 AM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,107
- Vote Rating
- 453
- Answers
- 3155
As long as the variables have a value before the lines are eval'd by the browser it will be fine. For example, this will work:
But if you have just the store and after the store is created you try and define or change the url, userid or accesskey variables then it will not update.Code:var url = 'someurl.com', userid = 1234, accesskey = 'abcdef'; var accountstore = Ext.create('Ext.data.Store', { storeId : 'Accountstore', model : 'accountmodel', proxy : { type : 'jsonp', url : 'php/vtiger_account.php', callbackKey : 'callback', extraParams : { url : url, userid : userid, accesskey : accesskey } reader : { type : 'json' }, } });Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
11 Dec 2012 1:46 AM #5
Yes, you`re right. I made the mistake to set a var same es a field of a singleton (Ext.Class).
// i use a singleton to store global vars, e.g. login data, urls, timeouts. how to make sure, singleton is instantiated before store will use them? i think at app load, singleton will be instantiated. Should i manually load the store and before i set extraParams? sorry for hijacking


Reply With Quote