简体   繁体   中英

Refresh table after ajax success with another SQL statement values without DataTable

i would like some guidance as to how to handle things after an ajax call.

I have a table with values showing numbers, those numbers are totals of other values. SQL statements wise, everything works. But I don't really understand how am I supposed to refresh that table when I click on buttons. These buttons are supposed to show the same table structure with different values, from another SQL query.

Here is what I have at the moment.

JS/AJAX

$(document).ready(function () {

var currentID;

$('.member_list li a').click(function() {
    currentID = $(this).attr('data-key-value');
    $.ajax({
        type: "POST",
        url: "index_report.php",
        data: { ID : currentID }
    }).done(function(response) {
        var table = $('.manage_table').DataTable();
        table.remove().draw();
    });
}); 

});

sample of buttons that should be pressed to get the new values:

<li><a href="" data-key-value="2" class="member_director">Henry</a></li>
<li><a href="" data-key-value="3" class="member_director">Joe</a></li>
<li><a href="" data-key-value="4" class="member_director">Hector</a></li>

and the line that launch the DB call for the individual data.

$temp_data_1 = $className>select_number_by_person($date_begin_month[$i],$date_end_month[$i], $_POST['ID']);

I figured out my problem was due to DataTable.

EDIT: Apparently, I can't use it with templates. I am currently using smarty, and all my table is auto generated with loops. For some reason, DataTable is only giving me Errors.

Any Idea how to do it without DataTable?

I am probably missing a huge chunk of code for this to work.

Thanks in advance of any advice.

I can see that you're using DataTable couldn't you do something like this?

var currentID;

$('.member_list li a').click(function() { 
      currentID = $(this).attr('data-key-value');
      dataTableUpdate();
});

function dataTableUpdate(id){
    var query = $.param({ID : currentID})
    var source = "index_report.php?" + query

    // Get API instance
    var table = $('.manage_table').DataTable(); 

    // Load data using API instance
    table.ajax.url(source).load();
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM