views:

23

answers:

2

Hello. I am using Zend Framework.
My task is to send JSON data from controller to Javascript.
I have an simple array:

$array = array('a' => 1, 'b' => 2);

After i am encoding this array to json format:

$jsonData = Zend_Json::encode($array);

But I don't know, how I can get this data in Javascript. I send an ajax request with jQuery. And in success I am trying to alert data.

Note:
If I do die($jsonData); in the Controller all good.

Thank you in advance!

+1  A: 

I'm not an expert in Zend Framework, but in simple php it can be done like this:

on the server, just do

 echo $jsondData;
 flush();

on the client use this: http://api.jquery.com/jQuery.getJSON/

Virtuality
Thanks. It works. But I have found good code for Zend.
Alexander.Plutov
+1  A: 

Use
$this->_helper->json($array);
instead of
$jsonData = Zend_Json::encode($array);

Alexander.Plutov