Refresh data without reloading the entire page


I am using codeigniter to load data on datatables, on the data table each row has a link that when clicked data is sent elsewhere. The data in that particular row should disappear and only links that have not been clicked remain. I have managed to do that with AJAXbut on success i am forced to reload the page on jQuery timeout


//Table headers here
<tbody class="tablebody">
    <?php foreach ($worksheets as $sheets) : ?>
            <td><?php echo $sheets->filename ?></td>
            <td class="bold assign">
                <?php echo $sheets->nqcl_number ?>&nbsp;&nbsp;&nbsp;
                <?php echo anchor('assign/assing_reviewer/' . $sheets->nqcl_number, 'Assign') ?>
                <a id="inline" href="#data">Assign1</a>
                <input type="hidden" id="labref_no" value="<?php echo $sheets->nqcl_number; ?>" />
            <td><?php echo $sheets->uploaded_by ?></td>
            <td><?php echo $sheets->datetime_uploaded ?></td>
    <?php endforeach; ?>

I would like that on AJAX success, the row of the datatables where the link was is dynamically removed from the table without page refresh.

    type: "POST",
    url: "<?php echo base_url(); ?>assign/sendSamplesFolder/" + labref,
    data: data1,
    success: function(data) {
        var content = $('.tablebody');
        $('div.success').slideDown('slow').animate({opacity: 1.0}, 2000).slideUp('slow');
        //Reload the table data dynamically in the mean time i'm refreshing the page
        setTimeout(function() {
            window.location.href='<?php echo base_url();?>Uploaded_Worksheets';
        }, 3000);
        return true;
    error: function(data) {
        $('div.error').slideDown('slow').animate({opacity: 1.0}, 5000).slideUp('slow');
        return false;

I have tried this but it loads two same pages. what's the work around?


You can use fnDraw() to force the datatable to re-query the datasource. Try this:

// store a reference to the datatable
var $dataTable = $("#myTable").dataTable({ /* Your settings */ });

// in the AJAX success:
success: function(data) {

Have a read of the fnDraw entry in the documentation.