Results 1 to 5 of 5

Thread: JSON load to DataView doesn't work

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Sencha User
    Join Date
    Feb 2012
    Posts
    26
    Answers
    1
    Vote Rating
    1
      0  

    Default Answered: JSON load to DataView doesn't work

    Any mistakes in the following code? I've been trying again and again but my JSON load doesn't work...I just see "Loading..." for several seconds then just a blank screen. I've tried loading via AJAX too, but that doesn't show the "Loading..." screen. Thanks in advance for the assistance.

    Sample of my JSON data:

    Code:
    {"households":[{"HHName":"Jim Smith Household"}])
    Code:
    Ext.regModel('Household', {
        fields: [
            {name: 'HHName',    type: 'string'}
        ]
    });
    
    var store = Ext.create('Ext.data.Store', {
            model    : 'Household',
            proxy: {
                type: 'jsonp',
                url: 'get_households.php',
                reader: {
                    type    : 'json',
                    root: 'households'
                }
            },
            autoLoad: true
        });
    
    var list = Ext.create('Ext.DataView', {
            store: store,
            itemTpl: '<p>household name is {HHName} </p>'
        });

  2. You are using JsonP so is the response valid for JsonP?

  3. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,336
    Answers
    3885
    Vote Rating
    1296
      0  

    Default

    Ext.regModel is not valid in ST2 and root config in the reader is now rootProperty:

    Code:
    Ext.define('Household', {
        extend : 'Ext.data.Model',
    
        config : {
            fields : [
                { name : 'HHName', type : 'string' }
            ]
        }
    });
    
    var store = Ext.create('Ext.data.Store', {
        model    : 'Household',
        autoLoad : true,
        proxy    : {
            type   : 'jsonp',
            url    : 'data/php.php',
            reader : {
                type         : 'json',
                rootProperty : 'households'
            }
        }
    });
    
    var list = Ext.create('Ext.dataview.DataView', {
        fullscreen : true,
        store      : store,
        itemTpl    : '<p>household name is {HHName} </p>'
    });
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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.

  4. #3
    Sencha User
    Join Date
    Feb 2012
    Posts
    26
    Answers
    1
    Vote Rating
    1
      0  

    Default Still having trouble

    Thanks for the reply, did not know that about ST2. I tried the new code but I'm still having an issue. I get the "Loading..." spinner for several seconds (15 or so) then a blank screen.

    The PHP file is in the same directory as my custom Sencha app.js. I've tried the filename "get_households.php" as well as the full path (http://mywebsite.com/get_households.php) to no avail.

    Any other ideas?

  5. #4
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,336
    Answers
    3885
    Vote Rating
    1296
      0  

    Default

    You are using JsonP so is the response valid for JsonP?
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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.

  6. #5
    Sencha User
    Join Date
    Feb 2012
    Posts
    26
    Answers
    1
    Vote Rating
    1
      0  

    Default

    It was not, after all, I was sending just plain JSON. Thanks, I've now learned the difference between JSON and JSONP...changed the type property to 'ajax' and I'm off and running.

    Thanks again for your help!

Posting Permissions

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