我想用数据库中的ajax更改一些文本,但不能正常工作.....
我的数据库结构
| id_paket_redeem | nama_paket | jumlah_poin | keterangan | id_tenant | tgl_kadaluarsa |
我的模特
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();
}
}
我的控制器
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;
}
我的观点+ 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());
}
})
});
答案 0 :(得分:1)
您忘了加载Super_Model
模型,您可以将$this->load->model('Super_model ');
添加到__construct
函数中,或者只添加函数api_get_poin
的开头。