title: How to convert this php normal code to codeigniter mvc
body: <p>I need help to convert this code to codeigniter MVC
  i have 2 file php
  index.php for viewer and cari_barang.php for model</p>
  
  <p>i have problem with file controller, I dont know how to get value post with ajax.</p>
  
  <p>this my PHP code index.php</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;script type="text/javascript" src="jquery-1.11.2.js"&gt;&lt;/script&gt; 
      &lt;script type='text/javascript' src='jquery.autocomplete.js'&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
  $(document).ready(function() {  
      $("#barang").keyup(function() {
          var kode    = $('#barang').val();
          $.ajax({
              type    : "POST",
              data    : "kode="+kode,
              url     : "cari_barang.php",
              dataType: "json",
              success: function(data){
                  $("#namabarang").val(data.namabarang); 
                  $("#hargabeli").val(data.hargabeli); 
              }
          });
      });
  
  });
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div class="demo" style="width: 450px;"&gt;
    &lt;div&gt;
    &lt;p&gt;Kode Barang : &lt;input type="text" id="barang" value="0001"&gt;&lt;/p&gt;
    &lt;p&gt;Nama Barang : &lt;input type="text" id="namabarang" size="50" disabled&gt;&lt;/p&gt;
    &lt;p&gt;Harga Beli : &lt;input type="text" id="hargabeli" size="15" align="right" disabled&gt;&lt;/p&gt;
    &lt;/div&gt;
    &lt;/div&gt; 
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>this code for cari_barang.php </p>
  
  <pre><code>&lt;?php
  
  mysql_connect("localhost","root","");
  mysql_select_db("barang");
  
  $kode   = $_POST['kode'];
  
  $sql    = mysql_query("select * from tbbarang where kodebarang='$kode'");
  $row    = mysql_num_rows($sql);
  
  if($row&gt;0){
      $r = mysql_fetch_array($sql);
      $data['namabarang'] = $r['namabarang'];
      $data['hargabeli'] = $r['hargabeli'];
      echo json_encode($data);
  
  }else{
      $data['namabarang'] = '';
      $data['hargabeli'] = '';
      echo json_encode($data);
  }
  ?&gt;
  </code></pre>
  
  <p>thanks before</p>