Not able to fetch value for edit Data Modal Form, from db through json data response
i need to fetch specific data from database and to be show in modal form ( Update / Edit Form ) , for i.g in form elemen i have this :
- <div class="form-group">
- <label for="nama" class="col-sm-2 control-label">Nama</label>
- <div class="col-sm-10">
- <input type="text" class="form-control" id="name" name="name" >
- </div>
- </div>
then function event onclick button submit .
- function editEmploy(id = null) {
- if (id) {
- //fetch data
- $.ajax({
- url:'pegawai/editpeg.php',
- type:'post',
- data:{'nip': id},
- dataType:'json',
- success:function(response) {
- $("#nama").val(response.name); // Not showing anything at modal form
- alert(response.name); // its shown name from database
- }
- });
-
- }else{
- alert("ERROR : blah ..blahh");
- }
- }
if i test with alert , it will show information data name from database , its mean fetching data from database have done well. How to send it to
<input type="text" class="form-control" i
d="name" name="name"
>
i have tried with this
- $("#name").val(response.name);
but when modal form show the input type shown anything / blank , no value , how to do this ? i mean send the value from response ajax to input type elemen form ?