irfanhans irfanhans - 11 months ago 50
SQL Question

Change text with ajax dropdown from database not working Codeigniter

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';

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>

<script type="text/javascript">
$("#id_paket_redeem").on('change', function() {
'url':'<?php echo site_url('member/Coin/api_get_poin') ?>',
'success': function(result) {


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 begging of function api_get_poin.