Results 1 to 2 of 2

Thread: Simple ajax request?

  1. #1
    Sencha User
    Join Date
    Dec 2011
    Posts
    1
    Vote Rating
    0
      0  

    Question 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 User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,050
    Answers
    3976
    Vote Rating
    1381
      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 @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

Posting Permissions

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