如何从jquery数据表发布数据

问题描述 投票:-1回答:1

我需要使用处理程序绑定jquery dataTable并且我通过下面给出的对象日志将参数发送到该处理程序。单击按钮我正在调用我编写下面代码的函数。单击按钮我需要有datatable.But问题是我无法绑定jquery数据表。请帮忙。无论如何将log作为参数传递给jquery datatable调用并在处理程序中捕获它?

var log = { LogType: logType, InstanceID: instanceId, StartDateTime: StartDateTime, EndDateTime: EndDateTime, UserId: UserId, SearchKey: SearchValue, ProjectID: projectId, ClassID: ClassId, MethodID: MethodId, UserName: UserName, FilePath: FilePath };

                $.ajax({
                    url: "LogManager.ashx",
                    dataType: "json",
                    responseType: "json",
                    data: { searchlog: JSON.stringify(log) },
                    success: function (data) {
                        $('#tblLogTable').DataTable({
                            "data": data,
                            "columns": [
                                { 'data': "stProjectName" },
                                { 'data': "stMethodName" },
                                { 'data': "stUserName" },
                                { 'data': "stFilePath" },
                                { 'data': "stClassName" },
                                { 'data': "inUserId" },
                                { 'data': "dtCreationTime" },
                                { 'data': "stLog" },
                                { 'data': "stInstance" },
                            ],
                            "language": {
                                "emptyTable": "There are no records at present.",
                            "zeroRecords": "There were no matching records found."
                        },
                            processing: true,
                            serverSide: false,
                            ordering: true,
                            paging: true,
                            searching: true
                            });


                        },


                    error: function (data) {
                        alert(data);
                    }
                });
javascript c# jquery datatable
1个回答
0
投票

它应该是另一种方式:

<script type="text/javascript" src="/assets/js/datatables.min.js"></script>
<script type="text/javascript" >

  $(document).ready(function () {
    $('#mytable').DataTable({
      processing: true,
      serverSide: true,
      ajax: {
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "/DataTables.aspx/Data",
        data: function (d) {
          return JSON.stringify({ parameters: d });
        }
      }
    });
  });
  </script>
© www.soinside.com 2019 - 2024. All rights reserved.