0
在视图,有这个基本的JavaScript/jQuery的:php/zend/json:如何获取视图然后将其作为json对象传递?
$('#jsoncallbtn').click(function() {
$.post('/mycontroller/json', {
someint: 123,
somestr: 'string'
}, function(datafromserver) {
alert(datafromserver.data1); // prints "test"
alert(datafromserver.data2); // prints "null"
}, "json");
});
在服务器端:
public function jsonAction()
{
$jsonArray = array('data1' => 'test',
'data2' => $this->render('anotheraction'));
$this->_helper->json($jsonArray);
}
有没有办法来渲染其他操作视图,并将其发送回JavaScript作为的一部分json对象?
它*可以*做这项工作,但也会有更好的办法。 – Phil
非常感谢!我一直在寻找这个:D – evilReiko
很高兴帮助。干杯。 –