Ajax.Reload-不刷新数据表

时间:2018-12-28 22:27:59

标签: javascript ajax asp.net-mvc datatables

从下拉列表中更改值后,我希望用新数据更新表。

$('table').DataTable().ajax.reload();

但是我遇到以下错误:

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

控制台浏览器中也出现下一个错误

Uncaught TypeError: Cannot set property 'data' of null
at sa (datatables.min.js:48)
at Sb (datatables.min.js:119)
at s.<anonymous> (datatables.min.js:120)
at s.iterator (datatables.min.js:111)
at s.<anonymous> (datatables.min.js:120)
at Object.reload (datatables.min.js:114)
at Object.success (pagos_tipos.js:72)
at i (jquery-3.2.1.min.js:2)
at Object.fireWith [as resolveWith] (jquery-3.2.1.min.js:2)
at A (jquery-3.2.1.min.js:4)

我正在尝试使用下一个代码刷新表:

                $("#ComboMagic").change(function () {
             var time = $('#ComboMagic').find('option:selected').val();

             $.ajax({
                url: "@Url.Action("ReloadTable","Facturas")",
                traditional: true,
                type: "POST",
                cache: "false",
                dataType: "json",
                data: { "time": time },
                success: function (response) {
                    $('#table').DataTable().ajax.reload();
                }
            });
        });

我正在使用ajax来提供我的数据表:

 $(document).ready(function () {
            $("#table").DataTable({
                    'scrollX': true,
                    'language': {
                        "lengthMenu": "Mostando _MENU_ registros",
                        "zeroRecords": "No se ha encontrado ningun registro",
                        "info": "Mostrando _PAGE_ de _PAGES_",
                        "infoEmpty": "No existe información disponible",
                        "infoFiltered": "(Filtrando de _MAX_ registros totales)",
                        "search": "Buscar:",
                        "paginate": {
                            "first": "Primera",
                            "last": "Ultima",
                            "next": "Siguiente",
                            "previous": "Anterior"
                        },
                        'ajax': {
                            "url": "@Url.Action("Index","Facturas")",
                            "type": "POST",
                            "dataSrc": ''
                        },

                        'columns': [
                            { data: "NumFactura"},
                            { data: "Sucursal"},
                            { data: "Fecha" },
                            { data: "GranTotal"},
                            { data: "EstadoFactura" },
                        ],
                        "order": [0, 'desc']
                    },
                });

1 个答案:

答案 0 :(得分:0)

像这样更改您的ajax代码,然后重试

$.ajax({
        url: "@Url.Action("ReloadTable","Facturas")",
        traditional: true,
        type: "POST",
        cache: "false",
        dataType: "json",
        data: { time: time },
        success: function (response) {
            $('#table').DataTable().ajax.reload();
        }
  });