0

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!

0

2 Answers 2

6

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

Sign up to request clarification or add additional context in comments.

Comments

1

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/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.