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.

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

报告相同问题?

悬赏问题

  • ¥15 Pwm双极模式H桥驱动控制电机
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题