0
I have this ajax function that keeps comparing the records of the pagina1.php with another pagina2.php, if in the pagina2.php has a new record it brings and adds in the table, until then everything ok, but the modal of this new object inserted in the table does not work, believe it is because the script jquery.min.js and bootstrap.min.js have already run.
Would you have some way to reload these scripts at the end of inserting the data in the table ?
$.ajax({
url: 'pagina2.php' ,
type: 'POST',
data: data_json,
dataType:'html',
success: function(data){
data = JSON.parse(data);
if(data != 'erro'){
if(data.length > 0) {
data_json.count_pms = parseInt(data_json.count_pms) + parseInt(data.length)
for (const obj of data) {
var inputs = '<tr class="item" data-target="#myModalcad' + obj .id_pms_exercicio + '">'
+ '<td style="background-color:'+ obj .cor_funcao + ';">'+ obj .nome_funcao + '</td>'
+ '<td>' + obj .id_pms_exercicio + '</td><td>'+ obj .numero_pms + '</td>' + '<td>'+ obj .dia_pms + '</td>'
+ '<td>'+ obj .descricao_pms + '</td>'
+ '<td>'+ obj .acao_esperada + '</td>'
+ '<div class="modal fade" id="myModalcad' + obj .id_pms_exercicio + '" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">'
+ ' <div class="modal-dialog" role="document">'
+ '<div class="modal-content">'
+ '<div class="modal-header text-center">'
+ '<h4 class="modal-title w-100 text-success" id="myModalLabel">Inserir Dec Cmd Exec</h4>'
+ '<button type="button" class="close" data-dismiss="modal" ><span aria-hidden="true">×</span></button>'
+ '</div>'
+ '<div class="modal-body">'
+ '<form method="POST" action="pagina1.php" >'
+ '<label for="dec_cmd_exec">Decisão do comando executante:</label>'
+ '<textarea class="form-control" type="text" name="dec_cmd_exec" ></textarea>'
+ '<input type="hidden" name="id_pms_exerc" value="">'
+ '<div class="modal-footer d-flex justify-content-center">'
+ '<button type="submit" class="btn btn-success" name="enviar">Enviar</button>'
+ '</div>'
+ '</form>'
+ '</div>'
+ '</div>'
+ '</div>'
+ '</div>'
+ '</tr>';
data_json.ids_pms = data_json.ids_pms + ',' + obj.id_pms_exercicio
$('#teste').prepend(inputs); // INSERI OS OBJETOS NA TABELA
$(document).on('click', '.item', function(){
var val = 'myModalcad' + obj.id_pms_exercicio
$(val).modal({ show: true }) // CHAMA MODAL pelo ID
})
}
}
}
}
});```