PDA

View Full Version : problem with Ext.data.JsonStore



stetou
8 Oct 2009, 9:55 AM
Hi,
With Ajax I load a php page that runs a sql query that populates an array and sent back a json like this


$arr = array('datereleve' => $row[0], 'nbdeces' => $row[1], 'nbhosp' => $row[2], 'nburgence' => $row[3], 'nbambulance' => $row[4] );
echo json_encode($arr);

The response returns only one row:
alert(xmlHttp.responseText);{"datereleve":"2009-09-01","nbdeces":"18","nbhosp":"486","nburgence":"2319","nbambulance":"483"}

My store is created like this:


store1 = new Ext.data.JsonStore({
fields:['datereleve', 'nbdeces', 'nbhosp', 'nburgence', 'nbambulance'],
data: [
//{"datereleve":"2009-09-01","nbdeces":"18","nbhosp":"486","nburgence":"2319","nbambulance":"483"}
xmlHttp.responseText
]
});


In data: parameter if I hard code it with {"datereleve":"2009-09-01","nbdeces":"18","nbhosp":"486","nburgence":"2319","nbambulance":"483"} it works (a chart is based on this store)
If I set it with xmlHttp.responseText it doesn't

when it doesn't work, With firebugs in the DOM elements, I see
store1-data-items-0-json = "{"datereleve":"2009-09-01","nbdeces":"18","nbhosp":"486","nburgence":"2319","nbambulance":"483"}"
The json string is not parsed.
Is the problem in my php page or in my js?
thanks for your help
Steve