Q:

How to retrive data from database using json in codeginter

Please i am trying to retrieve data form database using json in my codeingter application
Here is my model code
 public function getJsonFiles()
    {
        $query = $this->db->get('zd_files');
        return $query->result_array();
    }

here is my controller code
//* Fetching uploaded files jsson
    public function getFilesJson()
    {
        $data = $this->Extra_model->getJsonFiles();
        echo json_encode($data);
    }

here is my javascript code
$.ajax({                                      
      url: '<? php base_url(); ? >getFilesJson',                  //the script to call to get data          
      data: "",                        //you can insert url argumnets here to pass to api.php
                                       //for example "id=5&parent=6"
      dataType: 'json',                //data format      
      success: function(data)          //on recieve of reply
      {
        var id = data[0];              //get id
        var vname = data[1];           //get name
        //--------------------------------------------------------------------
        // 3) Update html content
        //--------------------------------------------------------------------
        $('#output').html("<b>id: </b>"+id+"<b> name: </b>"+vname); //Set output element html
      } 
    });

here my view file code
<div id="output">this element will be accessed by jquery and this text replaced</div>

it return this result

id: [object Object] name: undefined

Also i try to view the controller via the direct link and is echo this result

[{"file_id":"2","file_name":"1967761.png"}]

Please help. 

A:

You need to properly capture the values in the success callback of your AJAX. 
      success: function(data)          //on recieve of reply
      {
        var id = data[0].file_id;              //use file_id along with 0  index
        var vname = data[1].file_name;           //use file_name along with 0 index
. 
. 
. 
.