Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

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
up vote 6 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.by 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.