<?php
class ProductController extends Yaf_Controller_Abstract
{
public function viewAction()
{
// Assuming the request carries "X-Requested-With: XMLHttpRequest"
if ($this->getRequest()->isXmlHttpRequest()) {
$this->getResponse()
->setHeader("Content-Type", "application/json")
->setBody(json_encode(["id" => 17, "name" => "Yaf in Action"]));
return false;
}
}
}
?>
The above example will output
something similar to:
{"id":17,"name":"Yaf in Action"}