I had the same problem. I put this method in my base controller class:
/**
* Render JSON data for ajax
* If data is_bool then render json where key='result' and value=data
* @param mixed $data
*/
public function renderJSON($data)
{
if (is_bool($data))
{
$data = array('result' => $data);
}
header("Content-type: application/json;charset=utf-8");
echo CJSON::encode($data);
foreach (Yii::app()->log->routes as $route)
{
if ($route instanceof CWebLogRoute)
{
$route->enabled = false;
}
}
Yii::app()->end();
}
Then in my controller action instead of $this->render I call $this->renderJSON($withMyData);