1

I want to change some text with ajax from my database , but not work .....

My database structure

| id_paket_redeem | nama_paket | jumlah_poin | keterangan | id_tenant | tgl_kadaluarsa |

My Model

public function get($tabel='',$where='',$order='',$limit='',$from=''){
if (!empty($where)) $this->db->where($where);
if (!empty($order)) $this->db->order_by($order);

$query = $this->db->get($tabel,$limit,$from);

if ($query){
  return $query->result();
}
else {
  return array();
}
}

My Controller

public function redeem(){
    $id_user = $this->session->userdata('id_user');
    $data['read_coin'] = $this->Super_Model->get_nim('t_user.id_user ='.$id_user);
    $dataRedeem = array();
        $dataRedeem[""] = "[Pilih Paket Redeem]";
        $dataRedeemRead = $this->Super_Model->get('t_paket_redeem');
        foreach ($dataRedeemRead as $row) {
            $dataRedeem[$row->id_paket_redeem] = $row->nama_paket;
        }
        $data['get_redeem'] = $dataRedeem;
    $data['view']= 'v_member/Coin/v_paket_redeem';
    $this->load->view('index',$data);
}

function api_get_poin() {
    $poin = $this->input->post('id_paket_redeem');

    $result = $this->Super_model->get('t_paket_redeem','id_paket_redeem ='.$poin);

    $result = $result[0];

    echo $result->jumlah_poin;
}

My Part of View + Ajax

<form role="form" enctype="multipart/form-data" action="<?php echo site_url('member/coin/do_redeem')?>" method="post" >
  <div class="w3-half">
  <div class="col-md-8 col-xs-10 col-xs-offset-2">
  <h3>Pilihan paket reedem</h3>
      <?php echo form_dropdown("id_paket_redeem", $get_redeem,@$nim, 'class="form-control" id="redeem"');?>
  <h3>Point anda akan berkurang <p id="poin"></p> Poin</h3>
  <button type="submit" id="btnSubmit" class="btn btn-sm btn-white1 btn-block" >Submit</button>
  </div>
  </div>
  </form>


<script type="text/javascript">
$("#id_paket_redeem").on('change', function() {
  $.ajax({
    'url':'<?php echo site_url('member/Coin/api_get_poin') ?>',
    'type':'POST',
    'data':{
      id_paket_redeem:$("#id_paket_redeem").val()
    },
    'success': function(result) {
      console.log(result);
      $("#poin").val(result.trim());
    }
  })
});

9
  • where is the api_get_redeem function in your controller? Commented May 30, 2016 at 2:36
  • ok i made a change Commented May 30, 2016 at 2:38
  • But Still not work Commented May 30, 2016 at 2:39
  • did you get anything from print_r($result->jumlah_poin)? Commented May 30, 2016 at 2:53
  • get an error Undefined property: Coin::$Super_model Commented May 30, 2016 at 2:55

1 Answer 1

1

You forget to load the Super_Model model which you may add the $this->load->model('Super_model '); into the __construct function or just add the begining of function api_get_poin.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.