MedKostali MedKostali - 3 years ago 369
Ajax Question

reload datatable after ajax success

I use JQuery DataTable. I send data to datatable onclick in json file at ajax succes .the first click everything is good,But the next click I get only the right data ANd wrong value of dataTables_info it display always the first value of dataTables_info And paginatio AND row too from the first result.
This is the first display of data in datatable:

The first Click

ALL the next Click I get only right data:
For this exemple they are one result showing in picture below but everything else(info ,show,pagination) belong to first search showing in the first picture :
enter image description here

In the second Exemple When I click at any page of pagination I get the content of the first page result!!
This is my function ONclick:

$ ( '#ButtonPostJson' ).on('click',function() {

var forsearch = $("#searchItem").val();

processing: true,
serverSide: true,
type: 'post',
url: 'searchData.json',
dataType: "json",
data: mysearch,
/* bRetrieve : true,*/

success: function(data) {
$.each(data, function(i, data) {
var body = "<tr>";
body += "<td>" + + "</td>";
body += "</tr>";
$('.datatable-ajax-source table').append(body);

/*DataTables instantiation.*/
$('.datatable-ajax-source table').dataTable();

error: function() {
alert('Processus Echoué!');
afterSend: function(){
$('.datatable-ajax-source table').dataTable().reload();
/* $('.datatable-ajax-source table').dataTable({bRetrieve : true}).fnDestroy();
$('.datatable-ajax-source table').dataTable().clear();*/

I try everything and i dont know what I miss.
I use this jquery for datatable:

<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>


Answer Source

This link Refreshing data in jQuery DataTables

is verry helpfful ,I inspire from it to resolve my problem .

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download