View Full Version : JSONP and PHP

19 Jan 2011, 5:49 PM
Hi All,

Was wondering what is the best way to alter a local PHP file (which uses cURL to load XML data and convert to JSONP), so that a Ext.util.JSONP request can be done on the local file. If that makes sense?

I have done the following to get around the bloody JSONP errors with normal json data: -

Had to change the PHP code from: -

echo json_encode($data) ;

to: -

echo 'Ext.util.JSONP.callback('. json_encode($data) . ');' ;

This seems to work ok, but was wondering what anybody else has done???

Thanks in advance for any help...;)

30 Dec 2011, 4:13 AM
I've tried it and it's working like I wanted. Thanks !
My example :


$MyArray = array(
"results" => array(
0 =>array('name'=>'AAA','user'=>'sever_3d','image'=>'http://lorempixel.com/48/48/sports/'),
1 =>array('name'=>'BBB','user'=>'sever_3d','image'=>'http://lorempixel.com/48/48/city/'),
2 =>array('name'=>'CCC','user'=>'sever_3d','image'=>'http://lorempixel.com/48/48/animals/')
//echo json_encode($MyArray); // that is not woking !!!
echo 'Ext.util.JSONP.callback('. json_encode($MyArray) . ');' ; // that bad boy does ! cool !

30 Dec 2011, 10:21 AM
I do it like this, and it's working...

echo $_GET['callback'] . '('.json_encode($results).')';