Results 1 to 5 of 5

Thread: JsonP request

  1. #1
    Sencha User
    Join Date
    Mar 2012
    Posts
    10
    Vote Rating
    0
      0  

    Default 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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,553
    Answers
    3931
    Vote Rating
    1272
      0  

    Default

    Have you looked at the request? Are the params there?
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  3. #3
    Sencha User
    Join Date
    Jun 2012
    Posts
    49
    Answers
    7
    Vote Rating
    8
      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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,553
    Answers
    3931
    Vote Rating
    1272
      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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  5. #5
    Sencha User
    Join Date
    Jun 2012
    Posts
    49
    Answers
    7
    Vote Rating
    8
      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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •