I tell you: I have an Ajax request that brings me some data and loads it into a table. Between these data there is HTML code of a button, and when it loads, it loads super well. In the template, where the aforementioned table is loaded, I put "listen to the button" that loads the table with the event on ("click", function () ...); what the function does when the button is clicked, is to bring me other data with another HTML code of another button and load them perfectly into another table that I have. perfect, so there are no problems, now when I want to do the same process with the second button, nothing happens, the console.log or anything is not executed. I hope to be explicit enough, I will attach the code anyway. I hope they help me find an answer because I really could not. PDTA: An alternative solution that I have already taken and that works is to create normal functions, and in the html code to put the event onClick="functionParaExecute ()", however I would like to know precisely why it happens and how to solve it based on why. THANK YOU.
<script>
$("#btnDlg2").click(function () {
$("#dlgModal2").modal({backdrop: "static", keyboard: false});
});
$("#modal_cuotas_").hide();
var $table=$("#tabla_terceros");
$table.bootstrapTable('destroy');
$table.bootstrapTable({data:<?php echo $this->arrayss; ?>});
//Mostrar los planes de cuotas
$('.pay').on('click',function(){
var id=$(this).attr('id');
id=id.split('_');
id=id[0];
$.post("./inc/modulos/empresa/cartera/planes_cuotas.php", { nit: id},
function(data){
data=JSON.parse(data);
var $table=$("#tabla_pagar");
$table.bootstrapTable('destroy');
$table.bootstrapTable({data:data});
$("#modal_cuotas_").show();
});
});
$('.recaudo').on('click',function(){
console.log("Si entra");
/* var id_causacion=$(this).attr('id');
$.post("./inc/modulos/empresa/cartera/planes_cuotas.php", { id_cau: id_causacion},
function(data){
console.log(data);*/
});
</script>
<?php
if (!isset($_SESSION)) session_start();
require_once("../../../../librerias/Savant3.php");
$tpl = new Savant3(array('template_path' => "../../../../plantillas/"));
require_once ("../../../../class/database.class.php");
require_once ("../../../../class/cuota.class.php");
require_once ("../../../../class/tercero.class.php");
require_once ("../../../../class/ingreso.class.php");
$db=new Connection();
$cuota=new Cuota($db);
$tercero=new Tercero($db);
$ingreso=new Ingreso($db);
if (isset($_POST['id_cau'])) {
$datos_causacion=$ingreso->get_cau_IngresoByID($_POST['id_cau']);
echo "Hola";
print_r($datos_causacion);
}else {
//Trae todos los planes que tenga este tercero
if (isset($_POST['nit'])) {
$datos_cuota=$cuota->GetDatosCuotasByTercero($_POST['nit']);
foreach ($datos_cuota as $key => $value) {
$data_cuote[]=array('id_cuota' =>"".$value->id_cuota."",
'tasa_anual'=>"".$value->tasa_anual."",
'vlr_cuota'=>"".$value->vlr_cuota."",
'cuota_actual'=>"".$value->cuota_actual."",
'pagar'=>"<div class='btn-group' role='group' aria-label='Basic example'>
<button type='button' id='".$value->id_cau."' class='btn btn-success recaudo'><i class='fa fa-usd' aria-hidden='true'></i></button>
</div>");
}
echo json_encode($data_cuote);
}else {
//Trae todos los terceros con plaes
$terceros_unicos=$cuota->GetTerceros();
foreach ($terceros_unicos as $key => $value) {
$datos_tercero=$tercero->getUsuarioByNIT($value->nit_ter);
$array_datos[]=array('nit'=>"".$datos_tercero['nit_ter']."",
'nombre'=>"".$datos_tercero['nombre1_ter'].' '.$datos_tercero['nombres2_ter']."",
'pagar_nuevo'=>"<div class='btn-group' role='group' aria-label='Basic example'>
<button type='button' id='".$value->nit_ter."' class='btn btn-success pay'>Cobrar <i class='fa fa-usd' aria-hidden='true'></i></button>
<button type='button' id='".$value->nit_ter."' class='btn btn-primary new_plan'>Nuevo plan <i class='fa fa-plus' aria-hidden='true'></i></button>
</div>");
}
$tpl->arrayss=json_encode($array_datos);
$tpl->display('modulos/empresa/informe/cartera/planes_cuotas.tpl.php');
}}
?>
<div class="clearfix"></div>
<div class="col-md-6 col-sm-12 col-xs-12 slideInLeft">
<div class="modal-dialog modal-lg miClaseModal" id="modal_cuotas">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="titulo">Terceros con cuotas pendientes</h4>
</div>
<div class="box-body">
<table id="tabla_terceros" class="text-uppercase " data-toggle="table" data-sort-name="name" data-sort-order="desc" data-show-columns="true" data-toolbar="#toolbar" data-show-footer="false">
<thead class="text-left bg-primary">
<tr>
<th data-field="nit" data-width"" data-align="center">Nit</th>
<th data-field="nombre" data-width"" data-sortable="true" >Nombre</th>
<th data-field="pagar_nuevo" data-width"20%" data-align="center" data-sortable="true">Opciones</th>
</tr>
</thead>
</table>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
<div class="col-md-6 col-sm-12 col-xs-12 ">
<div class="modal-dialog modal-lg miClaseModal slideInRight" id="modal_cuotas_">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="titulo">Planes de cuotas</h4>
</div>
<div class="box-body">
<table id="tabla_pagar" class="text-uppercase " data-toggle="table" data-sort-name="name" data-sort-order="desc" data-show-columns="true" data-toolbar="#toolbar" data-show-footer="false">
<thead class="text-left bg-primary">
<tr>
<th data-field="id_cuota" data-align="center">Id cuota</th>
<th data-field="tasa_anual"data-align="center" data-sortable="true" >Tasa anual</th>
<th data-field="vlr_cuota" data-align="center" data-sortable="true">Valor cuota</th>
<th data-field="cuota_actual" data-align="center">Cuota actual</th>
<th data-field="pagar" data-width"20%" data-align="center" data-sortable="true">Recaudo</th>
</tr>
</thead>
</table>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>