ajax code not taking the data from table to second row

ajax code not taking the data from table to second row


hi guys i have a issue on ajax. where ajax can't work to take the values of second rows.

  i hope getting solve of this problem. thanks before guys. 
this's my code in model

   
  1. function getdata_barang($barcode) {
  2. $this->db1->where("barcode" ,$barcode);
  3. $query = $this->db1->get('tblmstbarang');
  4. if($query->num_rows()>0) {
  5. $data= array();
  6. foreach($query->result() as $row)
  7. {
  8. $data['barang_nama'] = $row->barang_nama;
  9. $data['harga_beli']= $row->harga_beli;

  10. echo json_encode($data);
  11. }
  12. } else{
  13. $data['barang_nama'] = "";
  14. $data['harga_beli']= "";
  15. echo json_encode($data);
  16. }
  17. }
this's my code in controller

    
  1. function getdata_barang(){
  2. $barcode = $this->input->post('barcode');
  3. $data=$this->Mbarang->getdata_barang($barcode); }
this's my code in view
      
  1. <script type="text/javascript">
  2. $(document).ready(function() {
  3. $('.form-control#barcode_2').keyup(function() {

  4. var barcode = $(this).val();
  5. $.ajax({
  6. type : "post",
  7. data : "barcode=" + barcode,
  8. url : "<?php echo base_url();?>index.php/master/barang/Cbarang/getdata_barang",
  9. dataType: "json",
  10. success: function(data){

  11. $('.form-control#barang_nama_2').val(data.barang_nama);
  12. $('.form-control#harga_beli_2').val(data.harga_beli);
  13. }
  14. });
  15. });
  16. });
  17. </script>
  18. <td><input type="text" class="form-control" id="barcode" name="barcode[]" value="<?php echo set_value('barcode['.$i.']') ;?>" onKeyUp="getValues()" ></td>
  19. <td><input type="text" class="form-control" id="barang_nama" name="barang_nama[]" value="<?php echo set_value('barang_nama['.$i.']') ;?>" onKeyUp="getValues()" disabled></td>
  20. <td><input type="text" class="form-control" id="harga_beli" name="harga_beli[]" value="<?php echo set_value('harga_beli['.$i.']');?>" onKeyUp="getValues()" disabled></td>

  21. <td><input type="text" class="form-control" id="barcode_2" name="barcode[]" value="<?php $a=set_value('barcode[0]') ; echo $a;?>"></td>
  22. <td><input type="text" class="form-control" id="barang_nama_2" name="barang_nama[]" value="<?php $a=set_value('barang_nama[0]') ; echo $a;?>" onKeyUp="getValues()" readonly></td>
  23. <td><input type="text" class="form-control" id="harga_beli_2" name="harga_beli[]" value="<?php $a=set_value('harga_beli[0]'); echo $a;?>" onKeyUp="getValues()" readonly></td>

  24. <td><input type="text" class="form-control" id="barcode_3" name="barcode[]" value="<?php echo $detail->barcode;?>"></td>
  25. <td><input type="text" class="form-control" id="barang_nama_3" name="barang_nama[]" value="<?php echo $detail->barang_nama;?>" onKeyUp="getValues()" readonly></td>
  26. <td><input type="text" class="form-control" id="harga_beli_3" name="harga_beli[]" value="<?php echo $detail->harga_beli;?>" onKeyUp="getValues()" readonly></td>