如何将其他参数传递给jQuery DataTable ajax调用?

编程入门 行业动态 更新时间:2024-10-27 08:25:52
本文介绍了如何将其他参数传递给jQuery DataTable ajax调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在加载jQuery DataTable时,我有以下代码。如何将其他参数传递给AJAX调用?以下问题和解答中建议的fnServerParams回调不起作用。也就是说,天真地使用 aodata.push()会导致 push is undefined(因为实际上aodata不是数组)。那么正确的方法是什么?

When loading a jQuery DataTable, I have the code shown below. How do I pass additional parameters to the AJAX call? The fnServerParams callback suggested in the questions and answers below does not work. That is, naively using aodata.push() results in "push is undefined" (because, indeed, aodata is not an array). So what's the correct way to do this?

相关问题:

  • 服务器端数据表。异步发送额外的参数
  • 了解数据表中的fnServerData
  • Datatables serverside. Send extra parameters asynchronously
  • Understanding fnServerData in Datatables

代码:

self.dataTable = self.dataTableContainer.DataTable({ "autoWidth": false, "bSort": false, "displayStart": 0, "paging": false, "lengthChange": false, "processing": true, "serverSide": true, "dom": "<'dataTables_header dashboard_alert_history__alertHeader'i>", "ajax": { url: getDataUri, error: onError, cache: false, "fnDrawCallback": onTableDrawn, }, "fnDrawCallback": onTableDrawn, "language": { "info": resources.alarmHistory, "infoEmpty": resources.alarmHistory, "infoFiltered": '' }, "columns": [ { "data": "timestamp", "mRender": function (data) { return IoTApp.Helpers.Dates.localizeDate(data, 'L LTS'); }, "name": "timestamp" }, { "data": "deviceId", "mRender": function (data) { return htmlEncode(data); }, "name": "deviceId" }, { "data": "ruleOutput", "mRender": function (data) { return htmlEncode(data); }, "name": "ruleOutput" }, { "data": "value", "mRender": function (data) { return htmlEncode(IoTApp.Helpers.Numbers.localizeFromInvariant(data)); }, "name": "value" }, ], "columnDefs": [ { "targets": [0, 1, 2, 3], "className": 'table_alertHistory_issueType', "width": "20%" } ], });

推荐答案

我忽略了RTFM。对于版本1.9和更高版本, fnServerParams 回调现在旧版较早。在最新版本的DataTables中,您可以使用DataTables文档中所述的ajax数据参数 。在下面的示例中,将 mykey 附加到 d 对象将达到目的:

I neglected to RTFM. The fnServerParams callback is now legacy for versions 1.9 and earlier. In the latest version of DataTables, you leverage the ajax data parameter as described in the DataTables documentation. In the example below, appending mykey to the d object will do the trick:

$(document).ready(function() { $('#example').DataTable( { "processing": true, "serverSide": true, "ajax": { "url": "scripts/server_processing.php", "data": function ( d ) { d.myKey = "myValue"; // d.custom = $('#myInput').val(); // etc } } } ); } );

更多推荐

如何将其他参数传递给jQuery DataTable ajax调用?

本文发布于:2023-11-23 10:39:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1621140.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   参数   jQuery   DataTable   ajax

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!