hey its me again..
now another matter about fetch data from db for provide information to modal form ( edit data ) not shown,
here's just part code fr each related page :
modal edit
ill try with first input type with id="name" name="name"
<!-- edit modal --> <div class="modal fade" tabindex="-1" role="dialog" id="editEmployModal"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title"><span class="glyphicon glyphicon-edit"></span> Update Pegawai</h4> </div> <form class="form-horizontal" action="pegawai/update.php" method="POST" id="updateMemberForm"> <div class="modal-body"> <div class="edit-messages"></div> <div class="form-group"> <!--/here teh addclass has-error will appear --> <label for="nama" class="col-sm-2 control-label">Nama</label> <div class="col-sm-10"> <input type="text" class="form-control" id="nama" name="nama" placeholder="Nama Pegawai"> <!-- here the text will apper --> </div> </div>
list_employee.php
here's just part of entire code for list employee, event onclick button to hold id each employee. If clicked it will show a modal edit
<li> <a type="button" data-toggle="modal" data-target="#editEmployModal" onclick="editEmploy(\''.$id.'\')"> <span class="glyphicon glyphicon-edit"></span> Edit</a> <li>
jquery file
function editEmploy(id = null) {
if (id) {
//fetch data from db
$.ajax({
url:'pegawai/fetch.php',
type:'post',
data:{'nip': id},
dataType:'json',
success:function(response) {
$("#name").val(response.name); //not working, at modal data name fr db isnt shown
$("#name").val('daniweb'); //not working, at modal set string name isnt shown too
}
});
//Update data pegawai
}else{
alert("ERROR : Refresh halaman kembali !!");
}
}
Fetch.php
<?php
include"../../config/koneksi.php";
$nip = $_POST['nip'];
$sql = "SELECT * FROM tbl_branch JOIN tbl_employe ON tbl_branch.los_code = tbl_employe.los_code WHERE tbl_employe.nip = $nip";
$query = mysqli_query($koneksi,$sql);
$result = mysqli_fetch_assoc($query);
// close the database connection
mysqli_close($koneksi);
echo json_encode($result);