created input form by json doesn't show in $_P

2019-08-12 15:27发布

问题:

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); // print all except input fields which retrieved from json

My php code:

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);

Script:

$(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");
            }                
        });
    });

回答1:

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.