我正在使用combodate jQuery库。当我从AJAX获取数据时,如何在字段中设置值?在文档中没有这样的例子。我试过$(selector).val('var from ajax')
,但它不起作用。这是我的代码:
<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');
}
});
答案 0 :(得分:1)
根据文档,您可以使用setValue()
方法:
设置新值。值可以是javascript Date()对象或options.format中的字符串。
$('[name="tanggal_selesai"]').combodate('setValue', response.TANGGAL_SELESAI).