06-27-2017, 08:05 AM
Controller :
function auto_barang(){
$id=$this->input->post('id');
$res= $this->barang_model->get_autocomplete($id);
//foreach ($res as $rows){
// $hasil['stock']=$rows['stock'];
//}
//$this->output->set_content_type('application/json');
$this->output->set_output(json_encode($res));
}
Script :
<script>
$(document).ready(function(){
$("#barang").change(function(){
$.post("<?php echo base_url()."index.php/pembelian/auto_barang"; ?>",
{
id:$("#barang option
elected").val()
}, function(data){
alert(data);
});
});
</script>
Output :
[{"id":"2","nama":"Lenovo ideapad 200","harga_beli":"2000000","harga_jual":"2500000","stock":"5"}]
How to if I just want to take stock value? Thank you !
function auto_barang(){
$id=$this->input->post('id');
$res= $this->barang_model->get_autocomplete($id);
//foreach ($res as $rows){
// $hasil['stock']=$rows['stock'];
//}
//$this->output->set_content_type('application/json');
$this->output->set_output(json_encode($res));
}
Script :
<script>
$(document).ready(function(){
$("#barang").change(function(){
$.post("<?php echo base_url()."index.php/pembelian/auto_barang"; ?>",
{
id:$("#barang option

}, function(data){
alert(data);
});
});
</script>
Output :
[{"id":"2","nama":"Lenovo ideapad 200","harga_beli":"2000000","harga_jual":"2500000","stock":"5"}]
How to if I just want to take stock value? Thank you !