0

On the view, there is this basic javascript/jquery:

$('#jsoncallbtn').click(function() {
     $.post('/mycontroller/json', {
          someint: 123,
          somestr: 'string'
     }, function(datafromserver) {
          alert(datafromserver.data1); // prints "test"
          alert(datafromserver.data2); // prints "null"
     }, "json");
});

On server side:

public function jsonAction()
{
    $jsonArray = array('data1' => 'test',
                       'data2' => $this->render('anotheraction'));
    $this->_helper->json($jsonArray);
}

Is there a way to render another action view and send it back for javascript as part of json object?

2 Answers 2

2

Sounds like the Action View-Helper could do the job.

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

2 Comments

It could do the job but there would also be a better way.
Thank you so much! I've been searching for this :D
1

You could create a separate Zend View instance and add the view's output to the JSON array. E.g something on along the lines of:

$view = new Zend_View();
$view->variable = "testing 123";
$html = $view->render('path/to/view/file.phtml');
$jsonArray["html"] = $html;
Zend_Json::encode($jsonArray);

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.