我有一个表单输入,其中value是该数组中的一个数组,我将向ajax和javascript代码获取一个值,以获取下一个表单的其他值, 请评估我的代码,因为它没有运行并且没有显示任何错误
<table>
<form>
<?php
for($i=1;$i<=$jml;$i++){?>
<tr>
<td>Jenis CI</td>
<td><select class="form-control" name="jenis2[]"id="jenis2[]" required>
<?php foreach($relasi as $row) { ?>
<option value="<?php echo $row->idJenisCI;?>"><?php echo $row->namaJenisCI;?>
</option><?php } ?>
</select>
</td>
</tr>
<tr>
<td>Nama CI</td>
<td><select class="id2 form-control" name="id2[]" required></select></td>
</tr>
<?php }?>
<tr align="center">
<td colspan="2"><input class="tombol" type="submit" name="submit" value="Simpan"></td>
</tr>
</form>
</table>
这是我的JavaScript和Ajax代码
<script type="text/javascript">
$(document).ready(function(){
$('#jenis2').change(function(){
var idJenisCI=$(this).val();
$.ajax({
url : "<?php echo base_url();?>index.php/C_ProyekAkhir/option",
method : "POST",
data : {idJenisCI: idJenisCI},
async : false,
dataType : 'json',
success: function(data){
var html = '';
var i;
for(i=0; i<data.length; i++){
html += '<option value="'+data[i].idCI+'-'+data[i].namaCI+'">'+data[i].namaCI+'</option>';
}
$('.id2').html(html);
}
});
});
});
</script>
答案 0 :(得分:0)
<script type="text/javascript">
$(document).ready(function(){
$('#jenis2').change(function(){
var idJenisCI=$(this).val();
$.ajax({
url : "<?php echo base_url();?>index.php/C_ProyekAkhir/option",
method : "POST",
data : {idJenisCI: idJenisCI},
async : false,
dataType : 'json',
success: function(data){
var decode_response = JSON.parse(data); // Add This New Line
var html = '';
var i;
for(i=0; i<data.length; i++){
html += '<option value="'+data[i].idCI+'-'+data[i].namaCI+'">'+data[i].namaCI+'</option>';
}
$('.id2').html(html);
}
});
});
});
</script>