0
I have the following table
<?php foreach ($this->views->clients as $client): ?>
<tr class="tr_<?= $client['id'];?>">
<td><?= $client['id']; ?></td>
<td><?= $client['name']; ?></td>
<td><?= $client['email']; ?></td>
<td><?= $client['nickname']; ?></td>
<td><?= $client['hour_value']; ?></td>
<td><?= $client['discount']; ?></td>
<td><?= $client['date_pagment']; ?></td>
<td><?= $client['cep']; ?></td>
<td class="text-center"><a href="" class="glyphicon glyphicon-pencil"></a></td>
<td class="text-center"><a href="" id="<?= $client['id']; ?>" class="getId glyphicon glyphicon-remove" data-toggle="modal" data-target="#myModal"></a></td>
</tr>
<?php endforeach; ?>
on this very page has a modal which is a form that inserts the dados that will appear in this table, I would like to know what is the best way to load these dados dynamically with AJAX, would also like the new records to be displayed at the top of the table.
Code AJAX to insert dados:
// Register and list clients script
$(function() {
$('#AjaxRequestClient').submit(function(e) {
e.preventDefault();
var form = $(this).serialize(); // Pode ser usado serializeArray()
var request = $.ajax({
method: "POST",
url: "/registerClient",
data: form,
dataType: "json",
success: function() {
}
});
request.done(function(e) {
$('#msg').html(e.msg);
$('.alert').removeClass('fade').addClass('alert-danger');
if (e.status) {
$('#AjaxRequestClient').each(function() {
$('.alert').removeClass('alert-danger').addClass('alert-success');
this.reset();
});
}
});
return false;
});
});
Which AJAX code you already have ready so far?
– Lucas Torres
I edited and put the ajax code that inserts the data in the table, I wanted after inserting it plays the new record la to top..
– wDrik
I always use the first option, with the callback Success.
– Leandro