Problem with multiplicated value
Problem with multiplicated value
Hi! Im working on a clients db with DataTables and I have the next problem, i made a search form in php that calls an ajax function to make datatable (datos_encontrados.leg_col_3 its a string with the html table), then i want to show an alert on buscar_cargas_legajo keyup
The first AJAX call its made when click on "#search_button" with the "#fila_id" input value, the table appears OK, and when i try keyup on "#buscar_cargas_legajo" a alert its shown, the problem come when i try to make another search with click on "#search_button", the table appears OK with the new data, but when i keyup on "#buscar_cargas_legajo" 2 alerts appear, and if i make a new search, 3 alerts apears and so on, any idea why it happen?
My code is:
$(document).ready( function () {
var pasada_imp_pdf = 0;
$("#search_button").click(function (e) {
e.preventDefault();
var nro_cuit = $("#fila_id").val(); // ID of row
$.ajax({
url: 'funciones.php?ac=search_id',
data: {
nro_cuit: nro_cuit // Data $_POST
},
dataType: 'json',
type: 'post'
}).done(function (datos_encontrados) {
// Respuesta
if (datos_encontrados) { // it its not null, NaN, undefined, 0 o empty
$("#leg_col_1").html(datos_encontrados.leg_col_1);
$("#leg_col_2").html(datos_encontrados.leg_col_2);
$("#leg_col_3").html(datos_encontrados.leg_col_3);
// Creacion DataTable de operaciones
var tabla_legajo_operaciones = $('#tabla_legajo_operaciones').DataTable({
"dom": 'Blt<"#suma_total">p', //Botones, longitud, tabla, div con id suma_total, paginas
"bPaginate": true,
"scrollX": true,
"sPaginationType": "full_numbers",
"iDisplayLength": 10,
"tooltip": true,
"colReorder": true,
});
$('#buscar_cargas_legajo').on('keyup', function () {
alert(pasada_imp_pdf);
});
}
});
return false;
});
});
Thank you very much for any help and sorry my bad english
Mariano.
This question has an accepted answers - jump to answer
Answers
Line 34 is creating additional handlers each time it's called - so each Ajax call adds one more. You could either call
off()
first to remove the earlier handler, or just ensure you only call it once (say with a global variable to check against)Colin
Thank you so much Colin! that made it!!