I'm dealing with some common optimizations in my system and I found a situation that intrigued me, every time I double clicked on the table and called a function to bring the complementary data of the client it doubled the amount of requests to the php , this happens because I was using the on
event, so I did some searching and found the one
method, which executes the method only once. this function seems to be new, in versions 1.7 of Jquery
it used only live
and it worked correctly.
So my question is, should I use one
if my intention is to call a function only once or should I use on
and off
?
$('#clientes tbody').on('dblclick', 'tr', function () { $('#cobradores tbody tr').removeClass('btn-success'); $(this).addClass('btn-success'); codigo = $(this).closest('tr').attr('id'); acao = 'update'; $("#clientes").modal('show'); }); $('#clientesModal').on('show.bs.modal', function () { if (acao === 'update') { dados = {PREUPDATE: true, CODIGO: codigo}; buscaCobradores(dados); } });