我使用 CodeIgniter,我有两个数据表(在两个单独的视图中。相同的 js、模型和控制器文件)
我可以用 SELECT 查询填充第一个表,它工作正常。
我的问题是我需要来自第一个表的数据(用于查询)(使用单击选择哪一行)来填充第二个表。我还不能让它工作。我已经在 phpMyAdmin 中执行了所需的 SELECT 查询并且它可以工作。
控制器文件
function refreshT2(){
    $id = $_POST['id'];
    $id = stripslashes($id);
    $id = mysql_real_escape_string($id);
    $this->load->model('model');
    $data=$this->model->getAllById($id);
    echo json_encode($data);
}
js文件
$(document).ready( function () {
    $("#table1").addClass("started");
    $("#table2").addClass("started");
    var t1Source = "controller/refreshT1";
    var t2Source = "controller/refreshT2";
    var oTablet1=$('#table1').dataTable({
        "sScrollX": "100%",
        "sPaginationType":"full_numbers",
        "bJQueryUI":true,
        "sDom": 'R<"H"lfr>t<"F"ip>',
        "bDeferRender": true,
        "bProcessing": true,
        "bServerSide": true,
        "aaSorting": [[ 0, "desc" ]],
        "sAjaxSource": ft1Source
    });
    $("#table1 tbody").click(function(event) {
        var iPos=oTablet1.fnGetPosition(event.target.parentNode);
        var aData=oTablet1.fnGetData(iPos);
        var id=aData[2];
        $('input[name=id]').val(id);
    /* When I click on the first dataTable the field 'id' is filled properly */
        var oTableft2 = $('#table2').dataTable({
            "sScrollX": "100%",
            "sPaginationType":"full_numbers",
            "bJQueryUI":true,
            "sDom": 'R<"H"lfr>t<"F"ip>',
            "bDeferRender": true,
            "bProcessing": true,
            "bRetrieve": true,
            "bDestroy": true,
            "bServerSide": true,
            "aaSorting": [[ 0, "desc" ]],
            "sAjaxSource": t2Source
        });
    } );
}
如果我需要提供更多信息/代码,请告诉我。
感谢您的时间。
编辑:当我切换$id = $_POST['id'];时它会起作用。如何检索这些数据?
我不想使用“按钮+动作”解决方案。如果它在 js 中工作,我将不需要任何发送/接收方法。我需要的是如何将参数传递给第二个表。