weixin_33736048 2018-07-20 22:04 采纳率: 0%
浏览 93

无法获取$ _POST数据

I've never run into this situation I'm having now. And am using this setup in another part of the site. I cannot figure out why I don't get any post data, my session variables never update.

Here is the html form, dynamically creating a row of check boxes:

$html .= '<form id="status_form">';
    foreach ($leads as $key => $type) {
        $html .= '<input type="checkbox" name"' . $key . '" id="' . $key . '" class="box_status" value="1"';
        if (something = true) {
            $html .= ' checked="checked"';
        }
        $html .= ' />';
        $html .= '<label class="checkbox-inline" for"' . $key . '">' . $type . ' (' . @$count[$key] . ')</label>';
    }
    $html .= '</form>';

    echo $html;

Each time a checkbox is checked, javascript is submitting the form to primarily update session variables and then reload the page:

function update_report() {
            var form_data = $("#status_form").serialize();
            $.ajax({
                type: 'POST',
                url: 'scripts/test.php',
                data: form_data,
                success: function() {
                    window.location.reload(true);
                }
            });
        }

        $('.box_status').change(function(){
            update_report();
        });

And here is the test.php file:

session_start();

if (isset ($_POST)) {

  $_SESSION['crm']['reports']['index'] = array();

    foreach ($_POST as $k => $v) {
        $_SESSION['crm']['reports']['index'][] = $k;
    }

    $_SESSION['post'] = $_POST;

    echo true;
}

I've double checked and the form is displayed correctly, the ajax makes the call, I've done "hello world" checks in test.php.. it even goes into the if(isset($_POST)) portion, but the session variables don't change, and if I assign $_POST to another session variable, it shows me nothing.

  • 写回答

1条回答 默认 最新

  • weixin_33712881 2018-07-20 23:10
    关注

    You have an error in your string concatenation:

    $html .= '<input type="checkbox" name"' . $key . '" id="' . $key . '" class="box_status" value="1"';
    

    name"' is supposed to be name="' You forgot the equal sign. jQuery serialize only takes input tags with names.

    Your solution:

    $html .= '<input type="checkbox" name="' . $key . '" id="' . $key . '" class="box_status" value="1"';
    

    Note: The best way to debug this sort of problem is to take a look at your generated html. When you load the page, check the page source. You also made the same error on your label tag.

    评论

报告相同问题?

悬赏问题

  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂