dthtvk3666 2014-11-20 09:42
浏览 35
已采纳

Jtable POST无法发送数据(使用PHP)

Having fun playing around with jtable,but got myself stuck in a bit of a rut.

I'm having a problem accessing data from a POST request. I'm trying to pass a variable from a field value in the table so I can make a custom SQL query.

My mainpage.php:

    $(document).ready(function () {
        //Prepare jTable
        $('#PeopleTableContainer').jtable({
            title: 'Trip data';
            ajaxSettings: {
            type: 'POST'
            },
            actions: {
                listAction: 'tableactions.php?action=list',
                updateAction: 'tableactions.php?action=update',
                deleteAction: 'tableactions.php?action=delete'
            },
            fields: {
                user_id: {
                    key: true,
                    edit: false,
                    list: false
                },
                name: {
                    title: 'Name',
                    edit: false,
                    list: false
                },
                trip_id: {
                    title: 'Trip ID',
                    list: false,
                    edit: false
                },
                trip_name: {
                    title: 'Trip Name',
                    width: '50%'
                },
                time: {
                    title: 'Start time',
                    width: '25%',
                    edit: false
                },
                date: {
                    title: 'Start date',
                    width: '25%',
                    edit: false
                }
            }
        });
        //Load person list from server
        $('#PeopleTableContainer').jtable('load');
    });   

I added the AJAX property to ensure it's set to post. Here's a portion of tableactions.php:

if($_GET["action"] == "list")
{
    //Get user ID
    $user_id = $_POST['user_id'];
    //SQL query
    $result = mysql_query("select * from userdata WHERE user_id=$user_id group by trip_id");
    //Add selected records into an array
    $rows = array();
    while($row = mysql_fetch_array($result))
    {
        $rows[] = $row;
    }
    //Return result to jTable
    $jTableResult = array();
    $jTableResult['Result'] = "OK";
    $jTableResult['Records'] = $rows;
    print json_encode($jTableResult);
}

I've tried changing $user_id to a correct value manually and the table works and displays the correct information. Really racking my brains to try and solve this.

Have I missed something obvious? Why can't I get a value from $_POST?

Any help would be greatly appreciated!

  • 写回答

1条回答 默认 最新

  • dongxili9934 2014-11-24 04:41
    关注

    I fixed this by cleaning my code and adding this into the table properties:

    ajaxSettings: {
                type: 'POST', 
                data: {'UserId': '<?php echo $userid;?>'},
                url: './tableactions.php'
                },
    

    Works fine now.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?