将参数传递给jQuery数据表中的sAjaxSource
我正在使用CodeIgniter,我有以下问题。
我在details.php
有一个控制器函数,它接受一个参数:
function details($id) { $this->datatables ->select('product_id, original_amount, quantity') ->from('orders'); echo $this->datatables->generate(); }
现在我需要从视图中调用它,即我希望DataTables像这样显示它:
$(document).ready(function() $('#example').dataTable({ ... 'sAjaxSource' : 'admin/data/details', ... });
那么,如何将参数传递给sAjaxSource
键,即$id
变量?
您应该使用fnServerParams
中指定的fnServerParams
。
$(document).ready(function() { $('#example').dataTable( { "bProcessing": true, "bServerSide": true, "sAjaxSource": "scripts/server_processing.php", "fnServerParams": function ( aoData ) { aoData.push( { "name": "more_data", "value": "my_value" } ); } } ); } );
我自己也在努力解决这个问题。 John Moses的回答对我不起作用,也提供了链接到新文档的链接,我认为这些链接不适用于旧版本的数据表。
虽然,我发现当前的服务器端处理工作类似于jQuery,其中带有“sAjaxSource”的旧版本不能以这种方式工作。
对我来说,我只是简单地在sAjaxSource
的url中添加了我的参数。 所以在你的示例代码中:
$customPHPvar = "mycustomvar";
在server_processing.php中
$_GET['customvar'];
- div中的jquery登录表单,无需刷新整页
- 如何使用localstorage / ajax jquery从第一页到第二页获取单选按钮值
- 使用jquery.load在codeigniter中使用ajaxvalidation失败后填充表单
- 如何停止通过$ .get发送的jquery ajax请求?
- 为什么我不能使用jQuery从unload事件处理程序激发AJAX请求?
- Javascript:只读取大型服务器文本文件的最后x行数
- 在hover时使用XML内容更新DIV
- jQuery AJAX和VBscript – 在jQuery AJAX中使用POST时无法获取VBscript变量中的值
- 使用jquery将yii2 ajax请求中的两个参数传递给控制器