View Full Version : Load data to the store via httpProxy

10 Mar 2012, 6:19 AM
Hello! I have MySQL test database with movies and want to load data from there and display them into the combobox
I've created a store and reader like this

var genres = new Ext.data.Store({
reader:new Ext.data.JsonReader({
proxy: new Ext.data.HttpProxy({
url: 'genres.php'

sufficient part of 'genres.php' page is looks like this

$query="SELECT * FROM genres";
while($obj = mysql_fetch_object($result)) {
$arr[] = $obj;
Echo '{rows:'.json_encode($arr).'}';

If I run this page in Firefox, I get the following output


now I'm trying to load data into the store


And I think I have error right here. I 've set a break point at the last line of code and when FireBug stops on it, I see, that there is no lines in the genres. Just to be safe I tried to use genres store in the combobox

xtype: 'combo',

But when I clicked combobox, all what I got is the spinning wheel and 'Loading' text.
I don't understand how


works. Is it goes to the 'genres.php' script and retrieves data from it's Echo call? And what's happening next? I am a bit newby in this techonology, so please, sorry for a maybe dumb questions.

10 Mar 2012, 9:09 AM
try changing your model and store to this style:

Ext.define (http://docs.sencha.com/ext-js/4-0/#%21/api/Ext-method-define)("User", {
extend: 'Ext.data.Model (http://docs.sencha.com/ext-js/4-0/#%21/api/Ext.data.Model)',
fields: [
'id', 'name'

Ext.create (http://docs.sencha.com/ext-js/4-0/#%21/api/Ext-method-create)('Ext.data.Store (http://docs.sencha.com/ext-js/4-0/#%21/api/Ext.data.Store)', {
model: 'User',
proxy: {
type: 'ajax',
url : 'users.json',
reader: {
type: 'json',
root: 'users'

Note that the reader is part of the proxy here and you just define the type using the type config in the reader.

Next. see the console of Firebug in Firefox. It shows you the requests and responses. you can see if the store actually sent a request and what the response was. You may also try the following to see the records in the store:

genres.on('load', function() {

10 Mar 2012, 10:06 AM
Farish (http://www.sencha.com/forum/member.php?277826-Farish), thank you a lot, your suggestion to change model and store hellped me to solve the problem! Thank you!

10 Mar 2012, 10:08 AM
glad i could help. you dont necessarily need to define a model separately. you may use the fields config in the store directly (but not in the reader as you had done in the original post).