jQuery Datatables Requested unknown parameter '0' for row '0' column '0'

Mal*_*dor 7 javascript asp.net jquery webforms datatables

I have the flat Json string produced by my aspx webpage..

[{"UserName":"ABENS"},{"UserName":"AILPAL"},{"UserName":"ANDREW.GUILLERMO"}.....(so on so forth)]
Run Code Online (Sandbox Code Playgroud)

I have declared the following html..

            <table id="tblUserAccountsManagement" class="display" cellspacing="0">                    
                         <thead>
                            <tr>
                                <th>UserName</th>

                            </tr>
                        </thead>                                

                    </table>
Run Code Online (Sandbox Code Playgroud)

I have the following Jquery...

  $(document).ready(function () {

        var tbl = $('#tblUserAccountsManagement').DataTable({

            "ajax": {

                "url": "AccountsManagementJSON.aspx",
                "dataSrc": ""

            },

            "columns": [

                { "data": 'UserName' }

            ],
            autofill: true,
            select: true,
            responsive: true,
            buttons: true,
            length: 10,

        });
    });
Run Code Online (Sandbox Code Playgroud)

Why does it still output the error?

Requested unknown parameter '0' for row '0' column '0'

I've read everything followed every troubleshoot there is, made sure that html and jQuery definition are intact.. why doesn't it still work?

What I don't understand is that I've tried this before here and it worked. I only had to add dataSrc: "" and that did the trick. I followed my previous example to the letter and now it does not work.

What's weird is that it does show the number of rows (39 rows like in the JSON) But it won't show content. Why is that?

Mal*_*dor 5

我已经解决了这个问题:我已经使用了aoColumnsmData设置(带有 MasterPages 的 Webforms)。

现在可以进行以下操作:

 $(document).ready(function () {

    var tbl = $('#tblUserAccountsManagement').DataTable({

        "ajax": {

            "url": "AccountsManagementJSON.aspx",
            "dataSrc": ""

        },

        aoColumns: [

            { mData: 'UserName' }

        ],
        autofill: true,
        select: true,
        responsive: true,
        buttons: true,
        length: 10,

    });
});
Run Code Online (Sandbox Code Playgroud)

  • 你的例子帮助我发现我的“列”结构放在了错误的地方——我把它埋在了“ajax”结构中。我需要投资一个 IDE。 (3认同)