title: Datatables do not show
body: <p>I'm newbie with jQuery and Ajax, but I found a example combination using CodeIgniter and datatables. I did try it the same way as the example but my datatables didn't show.</p>
  
  <p>Controller</p>
  
  <pre><code>class User extends CI_Controller {
      private $content;
      private $data;
      function __construct(){
          parent::__construct();
          $this-&gt;load-&gt;model('usermodel');
          $this-&gt;init();
      }
      function init(){
          if( $this-&gt;session-&gt;userdata('username') == '' ) redirect('auth');
          $this-&gt;data['username'] = $this-&gt;session-&gt;userdata('username');
      }
  
      function index(){
          //$this-&gt;content = $this-&gt;load-&gt;view('userListView', null, true);
          $this-&gt;content = 'users';
          $this-&gt;data['content'] = $this-&gt;content;
          //$this-&gt;data['users'] = json_encode($this-&gt;usermodel-&gt;getDataTable());
          $this-&gt;load-&gt;view('home', $this-&gt;data);
      }
  
      function data() {
          //print_r($this-&gt;usermodel-&gt;getDataTable());
          echo json_encode($this-&gt;usermodel-&gt;getDataTable());
          exit;
      }
  </code></pre>
  
  <p>Model</p>
  
  <pre><code>class Usermodel extends CI_Model {
      function getListALL(){
          $strSQL = "SELECT * FROM mst_user";
          $qData = $this-&gt;db-&gt;query($strSQL);
          return $qData;
      }
  
      function getSingle($user_id){
          $strSQL = "SELECT * FROM mst_user WHERE id = '" . $user_id . "'";
          $qData = $this-&gt;db-&gt;query($strSQL);
          return $qData;
      }
      function getDataTable() {
          $sTable   = "mst_user";
          $aColumns = array( 'id', 'username', 'fullname', 'email');
          $sIndexColumn = "id";
  
          /*
           * Paging
           */
          $sLimit = "";
          if ( isset( $_POST['iDisplayStart'] ) &amp;&amp; $_POST['iDisplayLength'] != '-1' ){
              $sLimit = "LIMIT ".addslashes( $_POST['iDisplayStart'] ).", " . addslashes( $_POST['iDisplayLength'] );
  
          }
          /*
             * Ordering
             */
          $sOrder = "";
          if ( isset( $_POST['iSortCol_0'] ) )
          {
              $sOrder = "ORDER BY  ";
              for ( $i=0 ; $i&lt;intval( $_POST['iSortingCols'] ) ; $i++ )
              {
                  if ( $_POST[ 'bSortable_'.intval($_POST['iSortCol_'.$i]) ] == "true" )
                  {
                      $sOrder .= "`".$aColumns[ intval( $_POST['iSortCol_'.$i] ) ]."` ".
                          addslashes( $_POST['sSortDir_'.$i] ) .", ";
                  }
              }
  
              $sOrder = substr_replace( $sOrder, "", -2 );
              if ( $sOrder == "ORDER BY" )
              {
                  $sOrder = "";
              }
          }
          /*
             * Filtering
             * NOTE this does not match the built-in DataTables filtering which does it
             * word by word on any field. It's possible to do here, but concerned about efficiency
             * on very large tables, and MySQL's regex functionality is very limited
             */
          $sWhere = "";
          if ( isset($_POST['sSearch']) &amp;&amp; $_POST['sSearch'] != "" )
          {
              $sWhere = "WHERE (";
              for ( $i=0 ; $i&lt;count($aColumns) ; $i++ )
              {
                  $sWhere .= "`".$aColumns[$i]."` LIKE '%".addslashes( $_POST['sSearch'] )."%' OR ";
              }
              $sWhere = substr_replace( $sWhere, "", -3 );
              $sWhere .= ')';
          }
          //echo $sWhere;exit;
  
  
          /* Individual column filtering */
          for ( $i=0 ; $i&lt;count($aColumns) ; $i++ )
          {
              if ( isset($_POST['bSearchable_'.$i]) &amp;&amp; $_POST['bSearchable_'.$i] == "true" &amp;&amp; $_POST['sSearch_'.$i] != '' )
              {
                  if ( $sWhere == "" )
                  {
                      $sWhere = "WHERE ";
                  }
                  else
                  {
                      $sWhere .= " AND ";
                  }
                  $sWhere .= "`".$aColumns[$i]."` LIKE '%".addslashes($_POST['sSearch_'.$i])."%' ";
              }
          }
  
  
          /*
             * SQL queries
             * Get data to display
             */
          $sQuery = "SELECT SQL_CALC_FOUND_ROWS `".str_replace(" , ", " ", implode("`, `", $aColumns))."` FROM $sTable $sWhere $sOrder $sLimit";
          //$rResult = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error());
          $stmt = $this-&gt;db-&gt;query($sQuery);
          //$stmt-&gt;setFetchMode(Zend_Db::FETCH_BOTH);
          $rResult = $stmt-&gt;result_array();
          //return $rResult;
          //echo $sQuery;exit;
  
          /* Data set length after filtering */
          $sQuery = " SELECT FOUND_ROWS() as FR";
          //$rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error());
          $stmt = $this-&gt;db-&gt;query($sQuery);
          //$stmt-&gt;setFetchMode(Zend_Db::FETCH_BOTH);
          //$aResultFilterTotal = mysql_fetch_array($rResultFilterTotal);
          $aResultFilterTotal = $stmt-&gt;result();
          //return $aResultFilterTotal;
          //$aResultFilterTotal = $stmt-&gt;fetchAll();
          $iFilteredTotal = $aResultFilterTotal[0]-&gt;FR;
          //echo $iFilteredTotal;exit;
          //print_r($aResultFilterTotal);exit;
  
          /* Total data set length */
          $sQuery = "SELECT COUNT(`".$sIndexColumn."`) as total FROM $sTable";
          //$rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error());
          //echo $sQuery;exit;
          $stmt = $this-&gt;db-&gt;query($sQuery);
          //$stmt-&gt;setFetchMode(Zend_Db::FETCH_BOTH);
          //$aResultTotal = mysql_fetch_array($rResultTotal);
          $aResultTotal = $stmt-&gt;result();
          $iTotal = $aResultTotal[0]-&gt;total;
          //echo $iTotal;exit;
  
  
          /*
             * Output
             */
          /* if(isset($_POST['sEcho'])) $sEcho = intval($_POST['sEcho']);
       else $sEcho = '';*/
          $output = array(
              "sEcho" =&gt; intval($_POST['sEcho']),
              "iTotalRecords" =&gt; $iTotal,
              "iTotalDisplayRecords" =&gt; $iFilteredTotal,
              "aaData" =&gt; array()
          );
  
          foreach ($rResult as $aRow)
          {
              $row = array();
              for ( $i=0 ; $i&lt;count($aColumns) ; $i++ )
              {
                  if ( $aColumns[$i] == "version" )
                  {
                      /* Special output formatting for 'version' column */
                      $row[] = ($aRow[ $aColumns[$i] ]=="0") ? '-' : $aRow[ $aColumns[$i] ];
                  }
                  else if ( $aColumns[$i] != ' ' )
                  {
                      /* General output */
                      $row[] = $aRow[ $aColumns[$i] ];
                  }
              }
              $output['aaData'][] = $row;
          }
          return $output;
      }
  
  }
  </code></pre>
  
  <p>View</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $(document).ready(function() {
          $(".button").button();
          $('#table_list').dataTable({
              "bJQueryUI": true,
              "bServerSide": true,
              "sServerMethod": "POST",
              "sPaginationType": "full_numbers",
              "sAjaxSource": "&lt;?php echo base_url();?&gt;index.php/user/data"
          });
      });
  &lt;/script&gt;
  &lt;?php //echo $users;?&gt;
  &lt;form class="form_element" action=""&gt;
      &lt;div id="content_header"&gt;&lt;h2&gt;User - List&lt;/h2&gt;&lt;/div&gt;
      &lt;div style="float:right;padding-bottom:5px"&gt;
          &lt;input type="button" value="Create New Record" onclick="window.location='user/form/add'" class="button"&gt;
      &lt;/div&gt;
      &lt;hr&gt;
  
      &lt;table id="table_list"&gt;
          &lt;thead&gt;
          &lt;tr&gt;
              &lt;td&gt;ID&lt;/td&gt;
              &lt;td width="200"&gt;User Name&lt;/td&gt;
              &lt;td&gt;Full Name&lt;/td&gt;
              &lt;td&gt;Email&lt;/td&gt;
          &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
          &lt;/tbody&gt;
      &lt;/table&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Home view</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Admin MOS Template&lt;/title&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;meta http-equiv="Copyright" content=""&gt;
  &lt;meta name="description" content="Admin MOS Template"&gt;
  &lt;meta name="keywords" content="Admin Page"&gt;
  &lt;meta name="author" content=""&gt;
  &lt;meta name="language" content="Bahasa Indonesia"&gt;
  
  &lt;link rel="shortcut icon" href="stylesheet/img/devil-icon.png"&gt; &lt;!--Pemanggilan gambar favicon--&gt;
  &lt;link rel="stylesheet" type="text/css" href="&lt;?php echo base_url();?&gt;include/mos_admin/mos-css/mos-style.css"&gt; &lt;!--pemanggilan file css--&gt;
  &lt;link type="text/css" href="&lt;?php echo base_url(); ?&gt;include/css/jquery.dataTables.css" rel="Stylesheet" /&gt;
  &lt;link type="text/css" href="&lt;?php echo base_url(); ?&gt;include/css/smoothness/jquery-ui-1.8.19.custom.css" rel="Stylesheet" /&gt;
  &lt;script type="text/javascript" src="&lt;?php echo base_url(); ?&gt;include/js/jquery-1.7.2.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="&lt;?php echo base_url(); ?&gt;include/js/jquery.dataTables.min.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;?php
  //print_r($users);
  //echo $strFormType;
  ?&gt;
  &lt;div id="header"&gt;
      &lt;div class="inHeader"&gt;
          &lt;div class="mosAdmin"&gt;
              &lt;?php $this-&gt;load-&gt;view('headerview');?&gt;
          &lt;/div&gt;
          &lt;div class="clear"&gt;&lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;div id="wrapper"&gt;
      &lt;div id="leftBar"&gt;
          &lt;?php $this-&gt;load-&gt;view('leftBarview'); ?&gt;
      &lt;/div&gt;
  
      &lt;div id="rightContent"&gt;
          &lt;?php
          if($content == 'changepass'){
              $this-&gt;load-&gt;view('changepassview');
          }
          else if($content == 'form'){
              $this-&gt;load-&gt;view('userformview');
          }
          else if($content == 'users'){
              $this-&gt;load-&gt;view('userlistview');
          }
          else{
              $this-&gt;load-&gt;view('rightContentview');
          }
          ?&gt;
      &lt;/div&gt;
  
      &lt;div class="clear"&gt;&lt;/div&gt;
  
      &lt;div id="footer"&gt;
          &lt;?php $this-&gt;load-&gt;view('footerview'); ?&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>