View Full Version : Requested JSON data from PHP

30 Nov 2010, 12:28 AM
Hello everybody,

i'm new in using ExtJs. I have a CakePHP project and want to set up an new Admin front end. Now I have problems with the requestes json data from my example php. Can someone help me? I have attached the project files based on an article of phpmagazin.

Is there a tutorial which describes the communication from front end to back end via php and json? Because there are a few other questions that i have like server side validation of forms with ExtJs handling of errors.

I've removed the extjs-3.3.0-files from the attachment.


30 Nov 2010, 5:58 AM
Without looking at your code, there are two options for generating JSON code with PHP (using either the native json_encode() function in PHP > 5.x, or the PHP_JSON package from PECL; or possibly there is something native in CakePHP).
- either you are trying to populate a store.

"rowcount" => somenumber,
"rows" => array(
array( "columnID" => value ),
), array( ... )
- or, you are trying to populate a form.

"success" => true,
"data" => array(
"fieldID" => value,
Encode your array and echo it back to your code. YMMV.

30 Nov 2010, 2:09 PM
Sorry, but i don't understand your Information.

1 Dec 2010, 3:59 AM
Does nobody knows why my example don't work?

1 Dec 2010, 8:20 AM
He just gave you the correct answer.... use json_encode() in php. See www.php.net for more information if you're not sure.

2 Dec 2010, 4:56 AM
I usually don't work with manually generated data, but here is my best guess.
Your json.php file looks ok, but not sure what version of PHP you're running. You might want to add headers for Cache-Control and Expires to solve issues with IE and GET requests.

header( 'Cache-Control: no-cache, must-revalidate' ) ;
header( 'Expires: ' . date( 'D d M Y H:i:s e' ) ) ;
header( 'Content-type: application/json' ) ;

Your store code is overly complicated. Simplify.

var columnModel = new Ext.grid.ColumnModel( {
columns: [
{ header: 'Bezeichnung', dataIndex: 'name', width: 10 },
{ header: 'Ort', dataIndex: 'place', editor: new Ext.form.TextField() },
{ header: 'Beginn', dataIndex: 'beginning', width: 10,
renderer: Ext.util.Format.dateRenderer( 'd.m.Y H:i:s' ) }
defaults: {
sortable: true
} ) ;

var eventStore = new Ext.data.JsonStore( {
fields: [
{ name: 'beginning', type: 'date', dateFormat: 'd.m.Y H:i:s' }
method: 'POST',
root: 'rows',
totalProperty: 'results',
url: '/json.php'
} ) ;

Since JsonStore inherits from Store, you don't need to configure the HttpProxy, if you use the url configuration. http://dev.sencha.com/deploy/dev/docs/source/Store.html#cfg-Ext.data.Store-url

Now, load Firefox with Firebug and make sure your json.php file is being loaded, and that the data returned is well-formed (put the data into jslint.org). YMMV