I just asked a question sort of like this
here. Really there shouldn't be much of a difference in how you make ajax requests in ZF than in any other way... framework or no framework. I think what I'm going to do is something like this:
[php]/**
* Application Controller
*/
class HockeyApp_Controller_Action extends Zend_Controller_Action
{
private $_ajax = false;
protected function _init()
{
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')
{
$this->_ajax = true;
}
}
}
class UserController extends HockeyApp_Controller_Action
{
public function deleteAction()
{
if (!$this->_isLoggedIn()) return;
$user = new Model_User;
$user->id = $this->getRequest()->getParam('id');
if ($user->delete())
{
/**
* If this request originated from XMLHttpRequest, than return a response in json
*/
if ($this->_ajax)
{
$status = 'success';
$output = Zend_Json::encode($status);
$this->getResponse()->setHeader("X-JSON", '(' . $output . ')'); // is this the right way to do this? I'm not even sure
return;
}
/**
* If the parser has made it here, than the request was just standard http, so forward them home or where ever they came from
*/
$this->_view->status = 'success';
$this->_forward('user', 'home');
return;
}
}
}[/php]