title: codeigniter Json table in view page not loading table
body: <p>trying to set crud with incodeigniter. I have never done it so I don't understand where I have gone wrong. I am able to insert data into the database and the <em>insert data window</em> is shown. I attached a picture of the result. The data gets retrieved from the database but not loaded into the table.</p>
  
  <p><img src="https://i.stack.imgur.com/P4QPp.png" alt="screenshot"></p>
  
  <p>Result:
  <img src="https://i.stack.imgur.com/Ad93h.png" alt="result screenshot"></p>
  
  <p><strong>CONTROLLER</strong></p>
  
  <pre><code>    function  get($id = null){
          $this-&gt;load-&gt;model('model_peca');
          $this-&gt;load-&gt;model('model_perfil'); 
          //  $this-&gt;load-&gt;view('telas/pecas/view_addvalue');         
          if ($id !=null) {
  
          $data = $this-&gt;model_peca-&gt;getData($id);
  
  
  
          } else {                    
          $data = $this-&gt;model_peca-&gt;getData();
              }
  
              $dados ['telaativa'] = 'pecas';
              $dados ['tela'] = 'pecas/view_addvalue';
              $this-&gt;load-&gt;view('view_home', $dados);
          echo json_encode($data-&gt;result_object());
  
          }
  
  
      function edit($id){
       $this-&gt;load-&gt;model('model_peca');
      $data = $this-&gt;model_peca-&gt;getData($id)-&gt;result_object();
  
      // }
      // else{
  
          $this-&gt;load-&gt;view('telas/pecas/view_edit',array('data'=&gt;$data));
      // }
      }
  
  function add(){
                  //$this-&gt;load-&gt;view('insert');
                  $this-&gt;load-&gt;model('model_peca');
                  $this-&gt;load-&gt;view('telas/pecas/view_insert');
  }
  
   function insert(){
      $this-&gt;load-&gt;model('model_peca');
              if ($this-&gt;input-&gt;post()) {
          $peca_parent_id = $this-&gt;input-&gt;post('peca_parent_id');
          $nr_peca = $this-&gt;input-&gt;post('nr_peca');
           //echo $peca_parent_id;
          // die;
          $insert = $this-&gt;model_peca-&gt;insert($peca_parent_id,$nr_peca);
          if ($insert &gt; 0) {
              $result = 200;
          }
          else{
              $result = 0;
          }
          echo json_encode(array("result"=&gt;$result));
  }
  }
  
      function deleteoperacao($id){
  
          $delete = $this-&gt;model_peca-&gt;delete($id);
          if ($delete &gt; 0) {
              $result = 200;
          }
          else{
              $result = 0;
          }
          echo json_encode(array("result"=&gt;$result));
      }
  
          function update($id){
              if ($this-&gt;input-&gt;post()) {
          $peca_parent_id = $this-&gt;input-&gt;post('peca_parent_id');
          $nr_peca = $this-&gt;input-&gt;post('nr_peca');
          // echo $barang;
          $insert = $this-&gt;model_peca-&gt;update($id,$peca_parent_id,$nr_peca);
          if ($insert &gt; 0) {
              $result = 200;
          }
          else{
              $result = 0;
          }
          echo json_encode(array("result"=&gt;$result));
      }
  }  
  </code></pre>
  
  <p><strong>MODEL</strong></p>
  
  <pre><code>function getData($id =null){
      if ($id ==null) {
      $data = $this-&gt;db-&gt;get('peca_value');
      }
      else{
      $data = $this-&gt;db-&gt;get_where('peca_value',array('id'=&gt;$id));
      }
      return $data;
      }
  
      function insert($peca_parent_id,$nr_peca){
      $data = array('peca_parent_id'=&gt;$peca_parent_id,'nr_peca'=&gt;$nr_peca);
      return $this-&gt;db-&gt;insert('peca_value', $data);
      }
  
  
      function update($id,$peca_parent_id,$nr_peca){
      $data = array('peca_parent_id'=&gt;$peca_parent_id,'nr_peca'=&gt;$nr_peca);
      $where = array('id'=&gt;$id);
      return $this-&gt;db-&gt;update('peca_value', $data,$where);
      }
  
      function delete($id){
      $where = array('id'=&gt;$id);
      return $this-&gt;db-&gt;delete('peca_value',$where);
      }
  }
  </code></pre>
  
  <p><strong>VIEW</strong></p>
  
  <pre><code>&lt;head&gt;
  
  &lt;link rel="stylesheet" href="assets/css/bootstrap/bootstrap.min.css"&gt;
  &lt;link rel="stylesheet" href="assets/datatables/dataTables.bootstrap.css"&gt;
  
  &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"&gt;
  &lt;!-- &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"&gt; --&gt;
  &lt;script src="http://code.jquery.com/jquery-3.2.1.min.js"&gt;&lt;/script&gt;
  &lt;!-- Latest compiled and minified JavaScript --&gt;
  &lt;script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"&gt;&lt;/script&gt;
  
  &lt;div class="content-wrapper"&gt;
    &lt;section class="content-header"&gt;
  
          &lt;h1&gt;Lista Peças 
  
  
          &lt;/h1&gt;
          &lt;ol class="breadcrumb"&gt;
                &lt;li&gt;&lt;a href="#"&gt;&lt;i class="fa fa-dashboard"&gt;&lt;/i&gt; Home&lt;/a&gt;&lt;/li&gt;
                &lt;li&gt;Peças&lt;/li&gt;
                &lt;li class="active"&gt;Lista pecas&lt;/li&gt;
  
          &lt;/ol&gt;
    &lt;/section&gt;
    &lt;/head&gt;         
    &lt;body&gt;
  
  
  &lt;div class="container" style="margin-top: 50px;"&gt;
  &lt;button class="btn btn-primary btn-act" data-name='add'  href="&lt;?php echo base_url('Home/add') ?&gt;"&gt; Nova Operação&lt;/button&gt;
  &lt;br&gt;
  &lt;br&gt;
  &lt;div class="row"&gt;
      &lt;div class="col-lg-12"&gt;
          &lt;div class="panel panel-default"&gt;
              &lt;h1&gt;&lt;/h1&gt;
              &lt;table class="table table-hover"&gt;
                  &lt;thead&gt;
                      &lt;th&gt;peca_parent_id&lt;/th&gt;&lt;th&gt;nr_peca&lt;/th&gt;&lt;th&gt;Editar/Apagar&lt;/th&gt;
                  &lt;/thead&gt;
                  &lt;tbody id="wrap"&gt;
  
                  &lt;/tbody&gt;
              &lt;/table&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>                                  </p>
  
  <pre><code>&lt;div id="myModal" class="modal fade" role="dialog"&gt;
    &lt;div class="modal-dialog"&gt;
  
  &lt;!-- Modal content--&gt;
  &lt;div class="modal-content"&gt;
    &lt;div class="modal-header"&gt;
      &lt;button type="button" class="close" data-dismiss="modal"&gt;&amp;times;&lt;/button&gt;
      &lt;h4 class="modal-title"&gt;&lt;/h4&gt;
    &lt;/div&gt;
    &lt;div class="modal-body"&gt;
  
    &lt;/div&gt;
    &lt;div class="modal-footer"&gt;
  
    &lt;/div&gt;
   &lt;/div&gt;
  
   &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>   &lt;!-------------------------------------------------------------------------------&gt;
  
  
  
  
  &lt;style type="text/css"&gt;
  body{
      background: #eee;
  }
  &lt;/style&gt;
  
  
  &lt;script src="../assets/js/jquery/jquery-2.2.3.min.js"&gt;&lt;/script&gt;
  
  
  &lt;script src="../assets/js/bootstrap/bootstrap.min.js"&gt;&lt;/script&gt;
  &lt;script src="../assets/datatables/jquery.dataTables.min.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p></p>
  
     
  
  <pre><code>&lt;script type="text/javascript"&gt;
  $(document).ready(function(){
      list();
  
  $(document).on('click',".update",function(){
      $.ajax({
          url: "&lt;?php echo base_url('Home/update'); ?&gt;"+$(this).data('id'),
          method: "POST",
          data: {
              peca_parent_id: $(".name").val(),
              nr_peca: $(".price").val()
          },
          dataType: 'json',
          success:function(r){
  
              if (r.result ==200) {
                  $("#myModal").modal('hide');
                  list();
              }
          }
      });
      });
  
      $(document).on('click',".insert",function(){
      $.ajax({
          url: "&lt;?php echo base_url('Home/insert'); ?&gt;",
          method: "POST",
          data: {
              peca_parent_id: $(".name").val(),
              nr_peca: $(".price").val()
          },
          dataType: 'json',
          success:function(r){
  
              if (r.result ==200) {
                  $("#myModal").modal('hide');
                  list();
              }
          }
      });
      });
     $(document).on('click','.btn-delete',function(){
     $.ajax({
      url: $(this).attr("href"),
      dataType : 'json',
      success: function(r){
          if (r.result == 200) {
                  $("#myModal").modal('hide');
                  list();
          }
      }
  });
  });
  
  
      function list(){
          $.ajax({
              url: "&lt;?php echo base_url('Home/get'); ?&gt;",
              dataType:"json",
              success: function(r){
                  var html ='';
                  var i;
  
                  for (i = 0;i &lt; r.length; i++) {
                      html += "&lt;tr&gt;";     
  
                      html += "&lt;td&gt;"+r[i].peca_parent_id+"&lt;/td&gt;";
                      html += "&lt;td&gt;"+r[i].nr_peca+"&lt;/td&gt;";
                      html += "&lt;td&gt;&lt;button data-name='edit' class='btn btn-act btn-update btn-success' href='&lt;?php echo base_url('Home/edit'); ?&gt;"+r[i].id+"'&gt;Edit&lt;/button&gt; &lt;button  class='btn-act btn btn-danger' data-name='delete' href='&lt;?php echo base_url('Home/deleteoperacao'); ?&gt;"+r[i].id+"'&gt;Hapus&lt;/button&gt;&lt;/td&gt;";
                      html += "&lt;/tr&gt;";
                  }
                  $("#wrap").html(html);
  
              }
          });
      }
      });
  
  
  // aksi btn-act 
      $(document).on("click", ".btn-act",function(){
      var name = $(this).data('name');
      // jika data-name sama dengan edit;
      if (name=='edit') {
                  $("#myModal .modal-title").html("Edit Data");
  
      $("#myModal .modal-body").load($(this).attr('href'));
      $("#myModal").modal('show');
  
      $("#myModal .modal-footer").html('&lt;button type="button" class="btn btn-danger btn-close" data-dismiss="modal"&gt;Tutup&lt;/button&gt;')
      }
      if (name=='add') {
      $("#myModal .modal-title").html("Tambah Data");
  
      $("#myModal .modal-body").load($(this).attr('href'));
      $("#myModal").modal('show');
      var href = $(this).attr("href");
      $("#myModal .modal-footer").html('&lt;button type="button" class="btn btn-danger btn-close" data-dismiss="modal"&gt;Tutup&lt;/button&gt;')
      }
      if(name=='delete'){
      $("#myModal .modal-title").html("Konfirmasi");      
      $("#myModal .modal-body").html("Apakah Anda Akan Menghapusnya?");
      $("#myModal").modal('show');
      var href = $(this).attr("href");
      $("#myModal .modal-footer").html('&lt;button href="'+href+'" type="button" class="btn btn-danger btn-delete" data-dismiss="modal"&gt;Hapus&lt;/button&gt;')
      }
        });
  </code></pre>
  
  <p></p>
  
  <p></p>