I use datatable
to list some data brought from a database which I have a button to edit, that when I press it shows me a modal window, which I look for the form that was just updated that table is updated without having to reload the page ..
try in the DONE
perform again ajax to list the data but I duplicate them. What alternative can exist so that as soon as you update that data, you do not have to press f5 and use window.location in javascript?
THAT'S HOW THE DATA IS READY IN THE DATATABLE
table_students= $('#table').DataTable({
"columnDefs": [
{
"targets": [ 0 ],
"visible": false,
"searchable": false
},
],
});
$.ajax({
url: 'list_students',
type: 'POST',
})
.done(function(response)
{
var answer= $.parseJSON(response);
for (var i = answer.length - 1; i >= 0; i--)
{
var rowNode = table_students
.row.add([
answer[i].stu_id,
answer[i].stu_nombre,
answer[i].stu_apellido,
answer[i].stu_correo,
'<center><button type="button" name="updatestudent" id="updatestudent" class="btn btn-warning"></button>',
])
.draw()
.node();
}
})
.fail(function() {
console.log("error");
});
THIS IS HOW I UPDATE
$("#updatestudent").submit(function()
{
event.preventDefault();
var data = $(this).serializeArray();
$.ajax({
url: 'data_updatestudent',
type: 'POST',
data: data,
})
.done(function(response) {
var answer= $.parseJSON(response);
if(answer)
{
$('#ModalUpdate').modal('hide');
alert("datos actualizados");
}
else
{
alert("error");
}
})
.fail(function() {
console.log("error");
})
});
I would appreciate the interest.