I have been having some trouble obtaining the html view rendered by an action
from an AJAX request. Initially, in my ajax-ed controller action, i was
checking if the request was XmlHttpRequest, and if so, disabling the layout
so just the portion of the view is returned. This was not working, so a
little research found pointers towards the AjaxContext helper. I have set it
up as follows:

Controller:
public function init(){
                        parent::init();
                        $this->flashMessenger = 
$this->getHelper('FlashMessenger');
                        
                    $ajaxContext = $this->_helper->getHelper('AjaxContext');
                $ajaxContext->addActionContext('view', 'html')
                            ->initContext();
                }

public function viewAction(){
                        if(!($id = $this->getRequest()->getParam('newsID'))){
                                $this->_redirect('index');
                        }
                        
                        $newsTable = new News_Table();
                        $select = $newsTable->select();
                        $select->setIntegrityCheck(false);
                        $select->from('news')->joinLeft('news_approved',
                                                                                
         'news.id = news_approved.news_id',
                                                                                
         array('approver_id' => 'staff_id', 'date_approved'));
                        $select->where('id = ?',(int) $id);

                        $rowset = $newsTable->fetchAll($select);
                        $this->view->assign('news', $rowset->current());
                }

The view script rendered for this is called view.phtml, so as per the
documentation, i copied the content and named a new view script
view.ajax.phtml. 

Although the correct action is being called (from jquery, with format=html
appended to the query string, although it would be nice to assume that no
format parameter = html by default, unless this can be set somewhere?) and
loading the correct ajax view script, it is not disabling the layout, and i
am getting a "page within a page".

Any pointers on what i'm doing wrong?
-- 
View this message in context: 
http://old.nabble.com/Returning-HTML-content-from-AjaxContext-tp26148891p26148891.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to