1. #1
    Sencha User
    Join Date
    Oct 2012
    Posts
    3
    Vote Rating
    0
    myat86 is on a distinguished road

      0  

    Default Cannot Load Store Data in Browser

    Cannot Load Store Data in Browser


    Hello everybody,

    Now I using Sencha Architect 2 and my problem is cannot load data in List. The JSON data return from WCF service and I used Ajax Proxy to get JSON data and used JSON reader, it can show in IDE but cannot show in browser. So I searched the solution in this forum, I found they suggest to use JSONP Store so I tried JSONP Store, JSONP Proxy and JSON Reader but it even cannot load data in IDE

    This is my store:
    Ext.define('MyApp.store.MyStore1', {
    extend: 'Ext.data.Store',

    requires: [
    'MyApp.model.mPerson'
    ],

    config: {
    model: 'MyApp.model.mPerson',
    storeId: 'MyStore1',
    proxy: {
    type: 'ajax',
    url: 'http://localhost:3535/Service1.svc/Person',
    reader: {
    type: 'json',
    rootProperty: 'GetResultsResult'
    }
    }
    }
    });
    Please help me .....

  2. #2
    Sencha - Architect Dev Team aconran's Avatar
    Join Date
    Mar 2007
    Posts
    9,263
    Vote Rating
    121
    aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold

      0  

    Default


    If you are trying to do cross domain requests, yes you will want to use Json-P. Are you wrapping your JSON in a callback on the server?
    http://en.wikipedia.org/wiki/JSONP

    Moving to help...
    Aaron Conran
    @aconran
    Sencha Architect Development Team

  3. #3
    Sencha User
    Join Date
    Oct 2012
    Posts
    3
    Vote Rating
    0
    myat86 is on a distinguished road

      0  

    Default


    Hi,
    This is my code:
    Ext.define('MyApp.store.MyStore1', {
    extend: 'Ext.data.Store',

    requires: [
    'MyApp.model.mPerson'
    ],

    config: {
    model: 'MyApp.model.mPerson',
    storeId: 'MyStore1',
    proxy: {
    type: 'jsonp',
    url: 'http://localhost:3535/Service1.svc/Person',
    reader: {
    type: 'json',
    rootProperty: 'GetResultsResult'
    }
    }
    }
    });
    When I tried to load data, I got this error

    SyntaxError: Parse error


    Source Class: http://localhost:3535/Service1.svc/P...sonP.callback2 Line 1

    The json data is :


    {"GetResultsResult":[{"Age":35,"FirstName":"Peyton","LastName":"Manning"},{"Age":31,"FirstName":"Drew","LastName":"Brees"},{"Age":29,"FirstName":"Tony","LastName":"Romo"}]}Please help me, I m very new for Sencha ArchitectThank you,Su Mon

  4. #4
    Sencha User loiane's Avatar
    Join Date
    Aug 2009
    Posts
    183
    Vote Rating
    52
    loiane is a jewel in the rough loiane is a jewel in the rough loiane is a jewel in the rough

      0  

    Default


    You need to wrap you json return inside the callback parameter sent by jsonp proxy in the server side code.

    For example (php):

    PHP Code:
    <?php    include("connect.php");
        
    $callback $_REQUEST['callback'];
        
    $query mysql_query("SELECT * FROM Contacts") or die(mysql_error());
        
    $rows = array('contacts' => array());    
        while(
    $contact mysql_fetch_assoc($query)) {        $rows['contacts'][] = $contact;    }
        
    header('Content-Type: text/javascript');
        echo 
    $callback '(' json_encode($rows) . ');';?>
    Last edited by loiane; 18 Oct 2012 at 5:25 AM. Reason: fixed code
    Sencha/Java evangelist
    Author of ExtJS 4 First Look and Mastering Ext JS books
    English blog: http://loianegroner.com
    Portuguese blog: http://loiane.com
    Sencha Examples: https://github.com/loiane

  5. #5
    Sencha User
    Join Date
    Oct 2012
    Posts
    14
    Vote Rating
    0
    mlourdes is on a distinguished road

      0  

    Default


    I want to populate a form with data from a store . I see the eye beside the store , but if I do in the initialize event something like this

    Code:
    var custStore=Ext.getStore('stTest');
    
    custStore.load();
    
    
    alert(custStore.getCount());
    I get 0 records .

    please I do not know what I am doing wrong . an example could be great

    my model and store are :
    Code:
    Ext.define('MyApp.model.mdtest', {
        extend: 'Ext.data.Model',
    
    
        config: {
            fields: [
                {
                    name: 'numberField',
                    type: 'int'
                },
                {
                    name: 'txtField',
                    type: 'string'
                }
            ],
            proxy: {
                type: 'ajax',
                url: 'Data/mdtest.json',
                reader: {
                    type: 'json',
                    rootProperty: 'test'
                }
            }
        }
    });
    
    Ext.define('MyApp.store.stTest', {
        extend: 'Ext.data.Store',
    
    
        requires: [
            'MyApp.model.mdtest'
        ],
    
    
        config: {
            autoLoad: true,
            model: 'MyApp.model.mdtest',
            storeId: 'stTest'
        }
    });
    Last edited by aconran; 13 Nov 2012 at 5:51 AM. Reason: add code tags

  6. #6
    Sencha - Architect Dev Team aconran's Avatar
    Join Date
    Mar 2007
    Posts
    9,263
    Vote Rating
    121
    aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold

      0  

    Default


    Stores are loaded asynchronously. When you execute the load method it is going to begin the load request, it won't be until a few seconds later that the request will return with the results.

    Both the Touch and Ext first application examples illustrate loading data into stores and binding to a visual widget.
    http://docs.sencha.com/architect/2/#...st_desktop_app
    http://docs.sencha.com/architect/2/#...rst_mobile_app
    Aaron Conran
    @aconran
    Sencha Architect Development Team

  7. #7
    Sencha User
    Join Date
    Oct 2012
    Posts
    14
    Vote Rating
    0
    mlourdes is on a distinguished road

      0  

    Default


    Now I am just trying with

    var customerStore=Ext.getStore('stCustomer');

    And if I call any method of customerStore it gives you can not execute method on undefine

    So do I have to do something like

    var customerStore=Ext.getStore('stCustomer');

    customerStore.load(function(){ callback(customerStore);