Postingan lainnya
Kelas Premium!
Belajar Javascript untuk website
Gunakan kupon "mulaijs" untuk diskon 75 ribu!
kenapa pas edit pop up ajax data masih kosong?
saya mau tanya gan ini kenapa ya pas edit pop up muncul datanya kosong tidak sesuai dengan idnya.
<a href="javascript:void(0)" title="Edit" onclick="edit('<?php $row->activity_detail_id;?>')" class="btn btn-outline btn-circle btn-sm purple" ><i class="fa fa-edit"></i> Edit </a>
my edit modal
<!-- begin pop update activity -->
<div class="modal fade left" id="modal_form">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h3 class="pull-left no-margin">Edit Activity</h3>
<button type="button" class="close" data-dismiss="modal" title="Close"><span class="glyphicon glyphicon-remove"></span>
</button>
</div>
<div class="modal-body">
<form class="form-horizontal" role="form" method="post" action="<?php echo base_url(); ?>input_activity/update">
<div class="form-group">
<label for="name" class="col-sm-3 control-label">Kategori:</label>
<div class="col-sm-9">
<?php $attributes = 'class = "form-control" id = "actype"';
echo form_dropdown('actype',$actype,set_value('actype',$detail[0]->activity_type),$attributes);?>
</div>
</div>
<div class="form-group">
<label for="activity" class="col-sm-3 control-label">Rincian Kegiatan: </label>
<div class="col-sm-9">
<textarea class="form-control" rows="3" name="activity_name" required><?php echo $detail[0]->activity_name;?></textarea>
</div>
</div>
<div class="form-group">
<label for="project" class="col-sm-3 control-label">Peruntukkan:</label>
<div class="col-sm-9">
<?php $attributes = 'class = "form-control" id = "project"';
echo form_dropdown('project',$project,set_value('project',$detail[0]->project_id),$attributes);?>
</div>
</div>
<div class="form-group">
<label for="portion" class="col-sm-3 control-label">Bobot:</label>
<div class="col-sm-4">
<input class="form-control" name="portion" value="<?php echo $detail[0]->portion;?>" required>
<input name="activity_detail_id" type="hidden" id="activity_detail_id" value="<?php echo $detail[0]->activity_detail_id;?>">
</div>
</div>
<div class="form-group">
<div class="col-md-offset-3 col-md-5">
<button type="submit" class="btn green">
<i class="fa fa-save"></i> Update</button>
<button type="button" class="btn default" data-dismiss="modal">Cancel</button>
</div>
</div>
</form>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
ajax:
<script type="text/javascript">
function edit(id)
{
$.ajax({
url : "<?php echo site_url('input_activity/edit/')?>/" + id,
type: "GET",
dataType: "JSON",
success: function(data)
{
$("[name='actype']").val(data.actype);
$("[name='activity_name']").val(data.activity_name);
$("[name='project']").val(data.project);
$("[name='portion']").val(data.portion);
$('#modal_form').modal('show'); // show bootstrap modal when complete loaded
},
error: function (jqXHR, textStatus, errorThrown)
{
alert('Error get data from ajax');
}
});
}
function reload_table()
{
table.ajax.reload(null,false); //reload datatable ajax
}
</script>
my controller
public function edit()
{
$id=$this->uri->segment(3);
$data=array(
'project' => $this->m_inputactivity->get_project(),
'actype' => $this->m_inputactivity->get_actype(),
'detail' => $this->m_inputactivity->per_id($id),
'
);
$this->output
->set_content_type('application/json')
->set_output(json_encode($data));
}
9 Jawaban:
sebelumnya sy mw tanya dulu gan. itu controller ga error apa. dibawah detail ada putik kebuka ga da penutupnya gitu
maaf gan tadi habis dihapus beberapa,udah ga ada putik koq
fokus ke id-nya dulu gan. coba inspect network, bener ga id yg dikirim ke php sesuai dengan yg di klik.
bagian ajax
$.ajax({
url : "<?php echo site_url('input_activity/edit/')?>/" + id,
apa bener begitu? slash '/' berulang dua kali. -> input_activity/edit//id
sesuai gan pas saya di klik tapi bingungnya datanya gak muncul dipop up
coba gini gan
<script type="text/javascript">
function edit(id)
{
$.ajax({
url : "<?php echo site_url('input_activity/edit/')?>/" + id,
type: "GET",
dataType: "JSON",
success: function(data)
{
$('#modal_form').modal('show'); // show bootstrap modal when complete loaded
$("#modal_form select[name='actype'] option").filter(":selected").val(data.actype);
$("#modal_form textarea[name='activity_name']").val(data.activity_name);
$("#modal_form select[name='project'] option").filter(":selected").val(data.project);
$("#modal_form input[name='portion']").val(data.portion);
},
error: function (jqXHR, textStatus, errorThrown)
{
alert('Error get data from ajax');
}
});
}
function reload_table()
{
table.ajax.reload(null,false); //reload datatable ajax
}
</script>
Jawaban Terpilih
data agan ada di dalam array, tapi agan ambil langsung
...
$("[name='activity_name']").val(data.activity_name);
...
kalau mw ambil datanya gini;
...
$("[name='activity_name']").val(data[0].activity_name);
...
ambil di array index [0] maksud sy gan
makasih agan @QaiserLab dan untuk semuanya
siang gan, saya mau bertanya kenapa data edit pop up tidak muncul ketika di klik? Mohon bantuannya gan..saya menggunakan framework codeigniter. Berikut gambarnya.
[img]https://skspace.sgp1.digitaloceanspaces.com/forums/images/form.png[/img] [img]https://skspace.sgp1.digitaloceanspaces.com/forums/images/pop up.png[/img]