ZF:禁用动作助手viewRenderer

In order to provide an ajax action I do the following:

    public function preDispatch()
    {
        if ($this->getRequest()->isXmlHttpRequest()) {
                Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer');
                Zend_Layout::getMvcInstance()->disableLayout();
        }           
    }

but the response comes with the following error: script 'async/tax.phtml' not found in path (/var/www/app/trunc/application/views/scripts/:./views/scripts/)

Why not using the Ajaxcontext action helper ? http://framework.zend.com/manual/en/zend.controller.actionhelpers.html#zend.controller.actionhelpers.contextswitch

// supposedly in your async controller
public function init() {
$ajaxContext = $this->_helper->getHelper('AjaxContext');
$ajaxContext->addActionContext('tax', 'html')
}

Then name your view "async/tax.ajax.phtml" and ensure that your ajax call ask for the html format.

That way you can even adapt your code to automatically respond with json, phtml or xml with the same controller/action.

  1. Have you checked whether the file tax.phtml exists in /var/www/app/trunc/application/views/scripts/ .
  2. If exists , then in tax.phtml place echo exit; at the bottom of the file.