PDA

View Full Version : display label error



habadon
29 Jun 2011, 12:20 PM
Hi!! aim new in extjs, and i search for this problem and no find a answer
well here is my problem:

i use Ext 3.3.1 and mysql 5.1

i need to display in a label the result of a php-mysql 'count' from a json
here is my code:

var storetotal = new Ext.data.Store({
reader: new Ext.data.JsonReader({
id: 'stotal',
root: 'contador',
fields: ['suma']
}),
proxy: new Ext.data.HttpProxy({
url: 'fwtotales.php'
}),
});
storetotal.load();


and i display the result here:

Ext.Ajax.request({
url: 'fwtotales.php',
method: 'POST',
success: function(obj){
var respuesta = obj.responseText;
Ext.get('lb').update(respuesta);.
},
failure:function(obj){
Ext.Msg.alert('Error!');
}
});

And this is the final display

[{"suma":"16"}]

i need to remove the "[{"suma":""}]", i only need the sum result, '16' for this example.

thanks for the help!!!

mitchellsimoens
29 Jun 2011, 3:36 PM
Please do not double post. Remove other thread from other forum. Also, post code wrapped in code BBCode tags.

habadon
29 Jun 2011, 4:32 PM
mmm so neither you know he?

skirtle
30 Jun 2011, 3:34 PM
You're making the same request in two different ways, once with a store and once with an Ajax request. This makes no sense. If your data has a total then configure a totalProperty on your JsonReader. Incidentally, you don't need to configure a separate JsonReader and HttpProxy, just use a JsonStore and put all of those config options on it directly.

If, however, you don't need the store and you just want to work with your JSON response using direct Ajax you'll need to decode the responseText using Ext.decode(), then pull out the property you want.

See the API docs for more info on the things I've mentioned.

habadon
30 Jun 2011, 4:06 PM
thanks man!!!

but i already found the answer, yes he was in the ajax.request, thanks!!

skirtle
30 Jun 2011, 4:15 PM
i already found the answer

If you find the answer to your own question then please post to the thread so that other people don't waste time trying to help you.

habadon
1 Jul 2011, 8:24 AM
sorry man, the next time a will post the solution if i found it first,
and dont waste time of ALL!!! THE PEOPLE!!! who take time to help me .....