Data does not show in dataTables

2019-08-02 16:01发布

问题:

No error but no data. Is there an option I need to add to make this work? my data uses the result from an ajax call.

Any suggestions?

Code:

    $.ajax({
        cache: false,
        url: "http://a.co.nz/GetTestDocs",
        data: '{'
          + '   "oldCompanyIdString": "' + selectOldCompanyId + '", '            
         + '    "effectiveDateString": "' + selectEffectiveDate + '", '
         + '    "endDateString": "' + selectEndDate + '",'
         + '   "userToken": "' + userToken + '"'
         + ' }',
        type: "POST",
        //jsonpCallback: "Value",
        contentType: "application/json",
        dataType: "json",
        error: function (jqXHR, textStatus, errprThrown) {
            //console.log(errprThrown);
            //window.location = location;
        },
        success: function (value) {
            if (value.GetTestDocsResult != null) {
                result = $.parseJSON(value.GetTestDocsResult);
                if (result.length == 0) {
                    alert("Your query did not return any data.");
                }
                else {
                    console.log(result);
                    bindDataTable(result.DocsList);                   
                }
            }
        }
    });

    function bindDataTable(data) {
    $('#docuList').dataTable({
        "processing": true,
        "ajax": data,
        "columns": [
            { "data": "Description" },
            { "data": "FileLocation" }]

    });
}

Help pls..my first time to use dataTables

回答1:

Replace "ajax": data, with "data": data,

function bindDataTable(data) {
    $('#docuList').dataTable({
        "processing": true,
        "data": data,
        "columns": [
            { "data": "Description" },
            { "data": "FileLocation" }
        ]
    });
}