Reputation: 20473
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?
Upvotes: 0
Views: 783
Reputation: 2246
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);
Upvotes: 1