Why My Ajax Cant Automatic Inserting Value to My Form ?
This is My Model
function get_pet_id($id_pet)
{
$this->db->select("*");
$this->db->from('pet');
$this->db->where('id_pet',$id_pet);
$result = $this->db->get();
return $result->result_array();
}
This Is My Controller
function get_pet()
{
$this->load->model('user_model');
$id_pet = $this->input->post('id_pet',TRUE);
$data['data']= $this->user_model->get_pet_id($id_pet);
echo json_encode($data);
}
And This is My View With JS
<div class="col-lg-3 col-sm-4 ml-auto mr-auto">
<div class="form-group">
<label for="Nama" class="bmd-label-floating">Pilih Hewan Peliharaan</label>
<select class="form-control" id="id_pet" name="id_pet" required>
<option value="">No Selected</option>
<?php foreach ($Pet as $H) { ?>
<option value="<?php echo $H['id_pet']; ?>"><?php echo $H['Nama']; ?></option>
<?php } ?>
</select>
<span class="bmd-help">Ras Hewan Apakah Dia</span>
</div>
</div>
<div class="col-lg-3 col-sm-4 ml-auto mr-auto">
<div class="form-group">
<label for="Jenis Hewan" class="bmd-label-floating">Jenis Hewan</label>
<br>
<input type="text" class="form-control" id="Jenis_Hewan">
<span class="bmd-help">Jenis Hewan</span>
</div>
</div>
and the JS script this
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript">
$('#id_pet').change(function() {
var id_pet = $(this).val();
$.ajax({
url: '<?php base_url('Master_Controller/get_pet'); ?>',
type: 'POST',
async: false,
data: id_pet,
dataType: 'json',
}).success(function(data) {
$(".Jenis_Hewan").val(data.Jenis_Hewan);
});
});
</script>
So After I Choose From Dropdown Next Form Should be Automatic Insert And Get Data From Dropdown Value But No Inserting Im new Using AJAX