I've a problem with my button delete. Picture
If I press delete in line 1, the alert will show it. But, if I press the button delete in line 2 - n, It will not show the alert.
This is my JS and HTML code
<script type="text/javascript">
$('#AlertDelete').click(function(e) {
swal({
title: "Yakin akan menghapus data?",
text: "Data yang sudah dihapus tidak akan bisa dikembalikan",
type: "warning",
showCancelButton: true,
confirmButtonColor: '#DD6B55',
confirmButtonText: 'Iya, hapus data!',
cancelButtonText: "Batalkan!",
confirmButtonClass: "btn-danger",
closeOnConfirm: false,
closeOnCancel: false
},
function(isConfirm) {
if (isConfirm) {
var data = $(this).serialize();
$.post('<?php echo base_url();?>index.php/agen/delete/<?php echo $row['id_agen'];?>', data);
swal("Terhapus!", "Data berhasil dihapus. Kamu akan diarahkan ke halaman sebelumnya secara otomatis", "success");
setTimeout("location.href = 'http://localhost/cvatikan/index.php/buku';",1000);
} else {
swal("Dibatalkan", "Hapus data dibatalkan", "error");
}
});
});
</script>
<h2 class="view-title">Kelola Agen</h2>
<div id="masonry" class="row">
<div class="module-wrapper masonry-item col-lg-12 col-md-12 col-sm-12 col-xs-12">
<section class="module module-headings">
<div class="module-inner">
<div class="module-heading">
<h3 class="module-title">Daftar Agen</h3>
<ul class="actions list-inline">
<li><a href="<?php echo base_url();?>index.php/Agen/manage"><span class="icon icon_plus"></span></a></li>
<!--<li><button type="button" class="btn btn-xs btn-primary" data-dismiss="modal"><span class="icon icon_plus"></span></button></li>-->
</ul>
</div>
<div class="module-content collapse in" id="content-1">
<div class="module-content-inner no-padding-bottom">
<div class="table-responsive">
<!-- di sini kontenny -->
<table id="datatables-1" class="table table-striped display">
<thead>
<tr>
<th>No</th>
<th>ID Agen</th>
<th>Nama Agen</th>
<th>Alamat</th>
<th>No. Telp</th>
<th>Keterangan</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php if(@$result):?>
<?php $i = 1;?>
<?php foreach ($result as $row):?>
<tr>
<td><?php echo $i++;?></td>
<td><?php echo $row['id_agen'];?></td>
<td><?php echo $row['nama_agen'];?></td>
<td><?php echo $row['alamat'];?></td>
<td><?php echo $row['no_telp'];?></td>
<td><?php echo $row['keterangan'];?></td>
<td>
<a href="<?php echo base_url();?>index.php/agen/manage/<?php echo $row['id_agen'];?>"class="btn btn-xs btn-primary"><i class="fa fa-pencil-square-o" aria-hidden="true"></i>Edit</a>
<a class="btn btn-xs btn-danger" id="AlertDelete"><i class="fa fa-trash"></i>Delete</a>
</td>
</tr>
<?php endforeach?>
<?php endif?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
I hope somebody can help me fix this problem. Thx before :)