DataTabes Refresh without refreshing page

DataTabes Refresh without refreshing page

TimothyVTimothyV Posts: 34Questions: 7Answers: 0

Hi, I have searched the forms and cannot find an answer to this can someone please help?

$(document).ready(function () { $('#example').DataTable(); });

$('#example').DataTable().clear();
$('#example').DataTable().ajax.reload();

Script Error: DataTables warning: table id=example - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1

Answers

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    Looks like the problem is that you are trying to use ajax.reload() without actually using the ajax. It has no URL to reference. You could try using ajax.url().load() to load data from a new URL.

    If this doesn't help please explain where you want to refresh the data from.

    Kevin

  • TimothyVTimothyV Posts: 34Questions: 7Answers: 0

    Kevin, thank you for the quick response. I apologize for the confusion, I populate the DataTable in the controller.

    var result = from m in db.Customer select m;

    return View(result);

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    So are you returning HTML? DataTables ajax.reload() requires that json be used.

    How are you populating the table initially? Are you using ajax for that? If you could link to your page that would be useful.

    Thanks,
    Allan

  • TimothyVTimothyV Posts: 34Questions: 7Answers: 0

    Allan, thank you for your response. I'm sorry but I do not understand.

    View:

    $(document).ready(function () { $('#example').DataTable(); });

    @foreach (var item in Model) {
    ...
    }

    Controller:

    var result = from m in db.Customer select m;
    return View(result);

This discussion has been closed.