2
I have a code in ajax to remove rows from a table, but to delete, I have to click the delete button and give a F5 so that the record is deleted in the current code. I tried to do in some ways presented in some posts here, but I could not get to delete the record without highlighting the page. Can someone help me?
function removeTr(id, callback){
$.ajax({
url: '/projetophp/controllers/controller-cliente.php',
dataType: 'json',
type: 'GET',
data: {
requisicao: "excluirClientes",
id:id
},
success: function(){
callback();
}
});
};
$(document).ready(function(){
/*Função para pegar os registros no banco de inserir na página*/
$.ajax({
url: '/projetophp/controllers/controller-cliente.php',
dataType: 'json',
type: 'GET',
data: {
requisicao: "listarClientes"
},
success: function(result) {
if(result){
var $cliente = $("#tabela tbody"),
options = "" ;
$.each(result, function( index, value ) {
options += ("<tr><td>" + value.id + "</td><td>" + value.cliente + "</td><td>" + value.email + "</td><td>"+ value.dominio +"</td><td>" + value.rds +"</td><td>"+ value.stack +"</td><td><button type='button' class='btn-editar btn btn-primary'>Editar</button><button type='button' value='delete' data-id='"+ value.id +"' class='btn-excluir btn btn-danger' data-toggle='modal'>Excluir</button></td></tr>");
});
$cliente.append(options);
/*Função para remover tr*/
$('.btn-excluir').on('click', function(){
event.preventDefault();
var $this = $(this);
removeTr($this.data('id'), function(){
$this.closest('#tabela tr').remove();
});
});
}
}
});
Your callback from the event
click
expects no argument (function()
) and you’re using the variableevent
which should be received by the function. Try changing its statement tofunction(event)
.– rdleal
if I understand your problem is to remove TR, which by far is a problem with php or ajax, however if you post HTML it may be possible to help you.
– Guilherme Nascimento