Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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!

share|improve this question

2 Answers

up vote 5 down vote accepted

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

share|improve this answer

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/

share|improve this answer
Thanks. It works. But I have found good code for Zend. – plutov Oct 30 '10 at 8:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.