jquery - 在数据表中设置来自Web服务的Json数据

标签 jquery json api web-services datatables

我必须将从 Web 服务返回的数据设置到数据表 HTML 表中。给出了代码。我尝试设置列,但这不起作用,显示“表中没有可用数据”。

HTML

     <table id="example" cellspacing="0" width="100">
                    <thead class="scrollmenu">
                        <tr>
                            <th>Sr.#</th>
                            <th>Reference</th>
                            <th>Type</th>
                            <th>Value Date</th>
                            <th>Amount</th>
                            <th>Transaction Type</th>
                            <th>Sender Bic</th>
                            <th>Receiver Bic</th>
                            <th>Receiver Account</th>
                            <th>Sender Account</th>
                            <th>Sender</th>
                            <th>Receiver</th>
                            <th>Payer's Participant</th>
                            <th>Beneficiary Participant</th>
                            <th>Creation Date</th>
                        </tr>
                    </thead>


                    <tbody>
                    </tbody>
                </table>

JavaScript

var datefrom = $('#dateFrom').val();
    var dateto = $('#dateTo').val();
    $.ajax({
        type: "POST",
        url: "/DashBoard/fetchDataDetails?flag="+flag+"&from=" + datefrom + "&" + "to=" + dateto,
         contentType: "application/json; charset=utf-8",
        success: function (data) {
            debugger;
            if (data.length > 0) {
                debugger;
                var abc = data;
                $('#example').DataTable({
                    "paging": true,
                    "ordering": true,
                    "info": true,
                    "columns": [
                        { "data": "system_reference_no" },
                        { "data": "mt_type" },
                        { "data": "system_refdate" },
                        { "data": "system_refamount" },
                        { "data": "TransType_Code" },
                        { "data": "sender" },
                        { "data": "receiver" },
                        { "data": "receiver_account" },
                        { "data": "sender_account" },
                        { "data": "sender_bic" },
                        { "data": "receiver_bic" },
                        { "data": "sender_bank" },
                        { "data": "receiver_bank" },
                        { "data": "creation_date" },
                    ]
                });

            }
            //  processingGif(false);
        },
        error: function (data) {
            // processingGif(false);
        }



    });

但这不起作用。我尝试了不同的选项,但无法使其发挥作用。需要帮助。

最佳答案

您需要使用 data 将数据传递到 DataTable选项。

$('#example').DataTable({
   // ... skipped ...
   "data": data 
});

关于jquery - 在数据表中设置来自Web服务的Json数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48381182/

相关文章:

Javascript幻灯片数组问题

javascript - lodash 不作为内部函数工作

javascript - (HTML)无法将浏览器高度存储到变量中并在用于 div 的类中使用相同的变量?

javascript - 在javascript中跨域发布二进制数据

swift - 添加坐标(从 UIViewController)到常量文件

javascript - 使用 jquery 插件逐页滚动

javascript - 在 ng-repeat 中对 JSON 对象值进行子字符串化

c# - 我可以在属性中指定路径以将类中的属性映射到 JSON 中的子属性吗?

java - Python 相当于 java 中的双冒号 (::) 运算符

api - 访问被拒绝 : no access to call this method