1. #1
    Sencha User
    Join Date
    Mar 2012
    Posts
    10
    Vote Rating
    0
    terrykoo is on a distinguished road

      0  

    Default 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

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,399
    Answers
    3549
    Vote Rating
    849
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Have you looked at the request? Are the params there?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Jun 2012
    Posts
    46
    Answers
    7
    Vote Rating
    3
    Malro is on a distinguished road

      0  

    Default


    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!

  4. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,399
    Answers
    3549
    Vote Rating
    849
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    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:

    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'
            },
        }
    });
    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.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  5. #5
    Sencha User
    Join Date
    Jun 2012
    Posts
    46
    Answers
    7
    Vote Rating
    3
    Malro is on a distinguished road

      0  

    Default


    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

Thread Participants: 2