如何仅为ajax请求返回JSON字符串[禁用视图]

I'm new to Codeigniter. I'm trying to integrate Extjs to Codeigniter. So when i make Ajax request the server should return only JSON string but instead server returns view [default] view along with the JSON string. Is it possible to disable view and return only data in codeignter. I have used zend framework before where i could disable view for ajax requests

I have tried some suggestions like in jQuery and CodeIgniter AJAX with JSON not working

In controller: die(json_encode($data_array));

It's not smart way doing that, but works perfect.

In your controller, at the end off the function, try:

$this->output->set_header('Content-type: application/json; charset=UTF-8');
$this->output->set_output(json_encode($array));