2
我正在使用combodate jQuery庫。當我從AJAX獲取數據時,如何在字段中設置值?在文檔中沒有這方面的例子。我試過$(selector).val('var from ajax')
,但它不工作。這裏是我的代碼:基於ajax響應的combodate.js上的setValue
<div class="form-group">
<label class="control-label col-md-3">Selesai</label>
<div class="col-md-9">
<div class="form-inline">
<div class="form-group">
<input name="tanggal_selesai" class="form-control combodate " type="text">
<span class="help-block"></span>
</div>
</div>
</div>
</div>
$('.combodate').combodate({
format: 'YYYY-MM-DD HH:mm',
template: 'DD/MM/YYYY HH : mm',
value: null,
minYear: 2015,
maxYear: new Date().getFullYear(),
yearDescending: true,
minuteStep: 1,
secondStep: 1,
firstItem: 'empty',
errorClass: null,
customClass: 'form-control',
roundTime: true,
smartDays: false
});
$.ajax({
url: "<?php echo site_url('members/it/request/ajax_edit/') ?>/" + id,
type: "GET",
dataType: "JSON",
success: function (response) {
$('[name="id"]').val(response.ID_REQUEST);
$('[name="nama"]').val(response.ID_KARYAWAN);
$('[name="tanggal_persetujuan"]').val(response.TANGGAL_PERSETUJUAN);
$('[name="tanggal_terima"]').val(response.TANGGAL_TERIMA);
$('[name="perkiraan_selesai"]').val(response.PERKIRAAN_SELESAI);
$('[name="tanggal_selesai"]').val(response.TANGGAL_SELESAI);
$('[name="pelaksana"]').val(response.PELAKSANA);
$('[name="keluhan"]').val(response.KELUHAN);
$('[name="catatan"]').val(response.CATATAN);
$('#modal_form').modal('show'); // show bootstrap modal when complete loaded
$('.modal-title').text('Edit Customer Data'); // Set title to Bootstrap modal title
},
error: function (jqXHR, textStatus, errorThrown) {
alert('Error get data from ajax');
}
});