1. #1
    Sencha User
    Join Date
    Dec 2011
    Posts
    1
    Vote Rating
    0
    makumaku is on a distinguished road

      0  

    Question Answered: Simple ajax request?

    Answered: Simple ajax request?


    Hi,
    First, I'm total newbie in Extjs and I just downloaded Extjs.
    I am trying get some data to Store using ajax.
    My js file
    **************************************
    Ext.require([
    'Ext.data.*'
    ]);

    Ext.onReady(function(){
    Ext.define('User', {
    extend: 'Ext.data.Model',
    fields: ['a', 'b']
    });

    var store = Ext.create('Ext.data.Store', {
    model: 'User',
    proxy: {
    type: 'ajax',
    url : 'json.php'
    }
    });

    store.load();
    alert(store.count());
    });
    ***********************************************

    and my php-file
    **********************************************
    <?php
    $output = array('a' => 'Apple', 'b' => 'Banana');
    header('Content-Type: application/x-json');
    echo json_encode($output);
    }?>
    **********************************************

    store.count() return always 0. What is wrong??

  2. Store loading is asynchronous meaning that doing a store.getCount() right after store.load() means that the loading isn't done. Two ways:

    Code:
    store.on('load', function() {
        console.log(store.getCount());
    });
    
    store.load({
        callback : function() {
            console.log(store.getCount());
        }
    });

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,647
    Vote Rating
    899
    Answers
    3575
    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


    Store loading is asynchronous meaning that doing a store.getCount() right after store.load() means that the loading isn't done. Two ways:

    Code:
    store.on('load', function() {
        console.log(store.getCount());
    });
    
    store.load({
        callback : function() {
            console.log(store.getCount());
        }
    });
    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.

Thread Participants: 1