Posts

Showing posts with the label AJAX

Zend Framework 2 AJAX: return JSON response from controller action. The proper way.

There is a lot of solutions over the web on how to return data on AJAX request in your Zend Framework 2 application. But none of them seems to be aware of the "right way" described in Zend Framework 2 manual - http://framework.zend.com/manual/2.0/en/modules/zend.mvc.examples.html#returning-early Implementation example: <?php namespace <YOUR_MODULE>\Controller; use Zend\Mvc\Controller\AbstractActionController; use Zend\Json\Json; class AjaxController extends AbstractActionController { public function testAction() { $data = array( 'result' => true, 'data' => array() ) return $this->getResponse()->setContent(Json::encode($data)); } }