将参数传递给jQuery数据表中的sAjaxSource

Ris*_*ddy 4 ajax jquery codeigniter datatables

我正在使用CodeIgniter,我有以下问题.

我有一个控制器函数,details.php其中有一个参数:

function details($id) {
    $this->datatables
         ->select('product_id, original_amount, quantity')
         ->from('orders');

    echo $this->datatables->generate();
}  
Run Code Online (Sandbox Code Playgroud)

现在我需要从视图中调用它,即我希望DataTables像这样显示它:

<script>
$(document).ready(function() 
  $('#example').dataTable({
    ...
    'sAjaxSource' : 'admin/data/details',
    ...
  });
</script>
Run Code Online (Sandbox Code Playgroud)

那么,如何将参数传递给sAjaxSource键,即$id变量?

Joh*_*ses 18

您应该使用文档中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" } );
        }
    } );
} );
Run Code Online (Sandbox Code Playgroud)