Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- Modal Tambah dan Edit DATA-->
- <div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
- <div class="modal-dialog modal-dialog-centered" role="document">
- <div class="modal-content">
- <div class="modal-header">
- <h5 class="modal-title" id="Label_Head">Tambah Data</h5>
- <button type="button" class="close" data-dismiss="modal" aria-label="Close">
- <span aria-hidden="true">×</span>
- </button>
- </div>
- <div class="modal-body">
- <input type="hidden" id="sh_csrf" name="<?php echo $this->security->get_csrf_token_name(); ?>" value="<?php echo $this->security->get_csrf_hash(); ?>">
- <div class="form-group">
- <label>Kamar<span class="text-danger" id="message_kamar"></span></label>
- <input type="text" class="form-control" id="kamar" placeholder="Kamar">
- </div>
- <div class="form-group">
- <label>Isi Max<span class="text-danger" id="message_isi_max"></span></label>
- <input type="text" class="form-control" id="isi_max" placeholder="Isi Max">
- </div>
- <div class="form-group">
- <label>Status<span class="text-danger" id="message_status"></span></label>
- <input type="text" class="form-control" id="status" placeholder="Status">
- </div>
- <div class="form-group">
- <label>Kondisi<span class="text-danger" id="message_kondisi"></span></label>
- <input type="text" class="form-control" id="kondisi" placeholder="Kondisi">
- </div>
- <div class="form-group">
- <label>Perlengkapan<span class="text-danger" id="message_perlengkapan"></span></label>
- <input type="text" class="form-control" id="perlengkapan" placeholder="Perlengkapan">
- </div>
- </div>
- <div class="modal-footer">
- <button type="button" class="btn btn-secondary" data-dismiss="modal">Keluar</button>
- <div id="button_action">
- </div>
- </div>
- </div>
- </div>
- </div>
- <script>
- var token = $('#sh_csrf').val();
- var id_data='';
- function f_edit(id){
- //$('#form_modal').prop("action","<?php echo base_url(); ?>kamar_akhwat/update");
- $.ajax({
- url : '<?php echo base_url();?>kamar_akhwat/update',
- cache : false,
- dataType : 'json',
- type : 'post',
- data : {id:id, <?php echo $this->security->get_csrf_token_name(); ?> : '<?php echo $this->security->get_csrf_hash(); ?>'},
- success : function (data){
- //kosongkan inputan
- kosong();
- //kosongkan pesan error
- token = data.token;
- message();
- if(data.ajax=='Sukses'){
- id_data=data.id;
- $('#kamar').val(data.kamar);
- $('#isi_max').val(data.isi_max);
- $('#status').val(data.status);
- $('#kondisi').val(data.kondisi);
- $('#perlengkapan').val(data.perlengkapan);
- empty_button_modal();
- $('#button_action').html('<button type="button" class="btn btn-primary" id="s_edit" onclick="s_edit()">Edit Data</button>');
- $('#Label_Head').html('Edit Data');
- show_modal();
- }else{
- $('#message_succes').html(data.ajax);
- }
- },
- });
- $('#sh_csrf').val(token);
- }
- </script>
- //controllers
- public function update()
- {
- $this->session->set_userdata('sh_csrf',$this->security->get_csrf_hash());
- $id= $this->input->post('id');
- $row = $this->Kamar_akhwat_model->get_by_id($id);
- if ($row) {
- $data = array(
- 'button' => 'Update',
- 'action' => site_url('kamar_akhwat/update_action'),
- 'home' => site_url(),
- 'href' => site_url('kamar_akhwat'),
- 'data_href' => "Al-Qur'an ",
- 'this_point' => "Update",
- 'ajax' => "Sukses",
- 'id' => set_value('id', $row->id),
- 'kamar' => set_value('kamar', $row->kamar),
- 'isi_max' => set_value('isi_max', $row->isi_max),
- 'status' => set_value('status', $row->status),
- 'kondisi' => set_value('kondisi', $row->kondisi),
- 'perlengkapan' => set_value('perlengkapan', $row->perlengkapan),
- 'token' => $this->security->get_csrf_hash()
- );
- header('Content-Type: application/json');
- echo json_encode($data);
- } else {
- $data=array('ajax'=>'Gagal mengambil data ajax','token' => $this->security->get_csrf_hash());
- header('Content-Type: application/json');
- echo json_encode($data);
- }
- }
Add Comment
Please, Sign In to add comment