json创建的输入表单不会显示在$ _POST中 [英] created input form by json doesn't show in $_POST

查看:109
本文介绍了json创建的输入表单不会显示在$ _POST中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 json 从数据库检索数据。当我点击一个选项,它检索一些输入表单。但是当我打印$ _POST它不显示这些输入。

I use json for retrieving data from database. When I click on an option it retrieves some input form. But when I print $_POST it doesn't show those inputs.

print_r($ _ POST); 打印从json检索的输入字段之外的所有字段

print_r($_POST); // print all except input fields which retrieved from json

我的PHP代码:

foreach($html->result() as $row){
   $html_input .= '<input name="' . $row->Feature_Eng_Name . '" type="text" style="color:#888" placeholder="'. $row->Feature_Name . '">';
   $html_input .= "<br>";                
}
$result = array('status' => 'ok', 'content' => $html_input);
echo json_encode($result);

脚本:

$(document).ready(function(){
        $("#maintype").click(function(){
            var base_url = "<?php echo base_url(); ?>" ;
            var isOption = $("option:selected").val();
            var cat_id = isOption;  
            if(isOption == ""){
                $("#feature_ajax").html("");                    
            }
            else{
                $.post(base_url + 'administrator/submit_product/ajax_get_feature_by_cat', {cat_id}, function(data){
                    if(data.status == 'ok'){                            
                        //alert("yes");
                        $('#feature_ajax').html(data.content);
                    }
                    else{
                        $('#feature_ajax').html("");
                    }
                }, "json");
            }                
        });
    });


推荐答案

确定在检查你的代码后,问题是你的FORM标签。他们被安置在错误的地方。确保如果您在div中打开表单标记,您需要将其关闭到同一个div中,而不是在外部,否则DOM会破坏它。

ok after inspecting your code, the problem was your FORM tags. They were being placed in the wrong places. Make sure if you open a form tag inside a div, you need to close it inside that same div, not outside or the DOM will break it.

这篇关于json创建的输入表单不会显示在$ _POST中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆