PDA

View Full Version : Simple ajax request?



makumaku
26 Dec 2011, 2:01 PM
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??

mitchellsimoens
26 Dec 2011, 5:43 PM
Store loading is asynchronous meaning that doing a store.getCount() right after store.load() means that the loading isn't done. Two ways:


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

store.load({
callback : function() {
console.log(store.getCount());
}
});