I am developing a project with bootstrap, php pdo and mysql, I have a datatable that reads from mysql, I have a button that says "New Revenue", it already makes the entry but I want to refresh or update the datatable so that it loads the new data without having to update the whole page.
When you make the new entry from the button, just refresh the datatable section and show the new entry.
For now I do it by refreshing the whole page with a window.location.href after receiving the ok from the jquery that made the entry to the base of the new row.
You already load it using the response of @ Maykol-Rivas, but I stop working an action, as you will see the table has the data and in the last column you have some actions, for now there is the action of "create history"
<tr class="odd gradeX">
<td id="pacedula">14</td>
<td>2</td>
<td>3</td>
<td></td>
<td>5</td>
<td class="center">
<li class="glyphicon glyphicon-eye-open"></li>
<li class="glyphicon glyphicon-edit"></li>
<li class="glyphicon glyphicon-remove"></li>
<li class="glyphicon icon-i-outpatient crearhistoria btn"></li>
</td>
</tr>
That I call her that from the js,
$(document).ready(function() {
cargar_datos();
});
function cargar_datos(){
$.ajax({
url: "php/mod_listar_datos.php",
type: "POST",
data: {opcion:1},
success: function(data) {
// En caso de que se ejecute
$('#tblPacientes > tbody').html(data);
}
});
}
$(".crearhistoria").click(function(){
var $cedula = $(this).closest("tr").find("#pacedula").text();
$.ajax({
url : 'php/mod_cre_his_paciente.php',
type: "POST",
method: "post",
data : "cedula="+ $cedula,
beforeSend: function(){
$('#labelMensajes').fadeIn(250).html('Enviando').delay(2500).fadeOut(250);
},
success:function(v) {
if(v==5){
$('#labelMensajespacientes').fadeIn(250).html('No se ha enviado cedula, intentelo nuevamente').delay(10000).fadeOut(250);
//window.location.href = "ad_docentes.php";
}else if(v==4){
$('#labelMensajespacientes').fadeIn(250).html('Ya se ha creado la histora Clinica del paciente con CI'+ $cedula).delay(5000).fadeOut(250);
}else if(v==3){
$('#labelMensajespacientes').fadeIn(250).html('Se ha creado la histora Clinica').delay(2500).fadeOut(250);
window.location.href="hclinica.php";
}else{
$('#labelMensajespacientes').fadeIn(250).html(v).delay(2500).fadeOut(250);
}
},
error: function() {
$('#labelMensajespacientes').fadeIn(250).html('Error: no se puedo realizar el ingreso').delay(2500).fadeOut(250);
}});});
But now it does not do anything that function, so I did before but what I did now does not work.