1
I have a table filled with codes:
- 1
- 2
- 3
When I click the delete record 1 button, it asks a question: "Do you want to delete the record?" I click no. I do the same for 2
But on 3, I click "yes"
The problem happens that is deleting the three records.
follows my ajax
$(".btn-remove").on("click", function(e){
e.preventDefault();
var rota = $(this).attr("href");
$('#modal-confirma').modal('show');
$("#modal-confirma").modal().find(".confirmado").on("click", function(){
alert(rota);
$.ajax({
url: rota,
type: "POST",
success: function(resp){
window.location.href = base_url + resp;
}
});
});
});
follows the html of the modal
<div class="modal fade" id="modal-confirma">
<div class="modal-dialog">
<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">Confirmação de Exclusão</h4>
</div>
<div class="modal-body">
Confirma exclusão do item?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger pull-left confirmado"
data-dismiss="modal">Sim</button>
<button type="button" class="btn btn-primary pull-left" data-dismiss="modal" aria-label="Close">
Não</button>
<!--<button type="button" class="btn btn-primary">Save changes</button>-->
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!-- /.modal -->
follows the table html with the records:
<table id="tabelacategoria" class="table table-bordered table-hover">
<thead>
<tr>
<th>#</th>
<th>Nome</th>
<th>Descrição</th>
<th>Opções</th>
</tr>
</thead>
<tbody>
<?php if(!empty($categorias)): ?>
<?php foreach($categorias as $categoria): ?>
<tr>
<td><?php echo $categoria->id_categoria; ?></td>
<td><?php echo $categoria->nome; ?></td>
<td><?php echo $categoria->descricao; ?></td>
<td>
<div class="btn-group">
<button type="button" class="btn btn-info btn-view" data-toggle="modal" data-target="#modal-default" value="<?php echo $categoria->id_categoria; ?>">
<span class="fa fa-search"></span>
</button>
<a href="<?php base_url()?>categorias/edit/<?php echo $categoria->id_categoria?>" class="btn btn-warning"><span class="fa fa-pencil"></span></a>
<a href="<?php base_url()?>categorias/delete/<?php echo $categoria->id_categoria ?>" class="btn btn-danger btn-remove"><span class="fa fa-remove"></span></a>
</div>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
You can also put html makes it easy for you to adjust
– Ari Santos
And if you click directly on 3, without clicking on the others before, what happens? Excludes only 3 or all as well?
– Woss
deletes only 3. I edited with html
– user102074
I had a problem with modal and the
on('click')
, for some reason he kept recording how many times I opened the modal, and when I was going to perform an action in the modal, the action was executed several times according to how many times I opened the modal, to resolve I changed the.on('click')
, for$("").click()
, for me solved.– Vinicius