Ajax响应html数据是否可以在Codeigniter中发布?

In ajax call the div is repalcing fine but am not able to get the post values of the replaced div when i am submiting the form. My html form like this

<form action="<?php echo base_url('addorder');?>" method="post" enctype="multipart/form-data">
    <div class="input-group" id="app_details">
        <input type="text" class="form-control" name="order_assignment_appraiser" id= "order_assignment_appraiser" value="<?php echo set_value('order_assignment_appraiser');?>"> 
        <input type="hidden" id="order_assignment_appraiser_id" name="order_assignment_appraiser_id" value=<?php echo set_value('order_assignment_appraiser_id')?>>   
        <span class="input-group-btn">
            <a class="btn btn-default" id='addappr' href="<?php echo base_url('addappraiser?formtype=new')?>"><i class="fa fa-plus-square"></i></a>
        </span>
    </div>
    <button class="btn btn-info" id="savebutn" name='saveandclose' value='saveclose' type="submit"><i class="fa fa-save"></i> SAVE &amp; CLOSE </button>
</form>

Ajax code is like this

$.ajax({
  type: "GET",
  url: baseurl + "orderdetails/getajaxresponse",
  data: 'app_id=' + id,
  success: function(data) {
    $('#app_details').html(data);
    // $('#app_details').replaceWith(data); // I tried like this also
  }
});

and my controller action is like this

public function getajaxresponse()
{
    if($_GET['app_id']!='' && $_GET['app_id']>0)
    {
        $order_appraiser_id=$_GET['app_id'];
        if($order_appraiser_id!='' && $order_appraiser_id>0)
        {
            $appraiser_details=$this->appraiser_model->get_appraiser_by_id($order_appraiser_id);
            $data['app_details']=$appraiser_details;
            $this->load->view('projectname/dashboard/appraiserdetailsajax', $data);
        }
    }
}

and my Ajax replaced file appraiserdetailsajax like this

<div class="input-group" id="app_details">
  <input type="text" class="form-control" name="order_assignment_appraiser" id="order_assignment_appraiser" value="<?php echo $app_details['appraiser_first_name'].' '.$app_details['appraiser_last_name']; ?>">
  <?php echo form_error( 'order_assignment_appraiser'); ?>
  <input type="hidden" id="order_assignment_appraiser_id" name="order_assignment_appraiser_id" value=<?php echo $app_details[ 'user_id']; ?>>
  <span class="input-group-btn">
    <a class="btn btn-default" id='addappr' href="<?php echo base_url('addappraiser?formtype=new')?>"><i class="fa fa-plus-square"></i></a>
     </span>
</div>

I am using fancybox for new addition appraiser.This link calls fancybox <?php echo base_url('addappraiser?formtype=new')?> in the div.On Close of fancybox i am calling Ajax function.Fancybox code is like this

$(document).ready(function(){
    $('#addappr').live('click', function(){ 
        $(this).fancybox({
            'width'             : '70%',
            'height'            : '90%',
            'autoScale'         : false,
            'transitionIn'      : 'none',
            'transitionOut'     : 'none',
            'type'              : 'iframe',
            'onCleanup': function(){

                feeid = $('#parent_app_client_id').val();

            },
            'onClosed': function() {
                 /*var url = baseurl+"addorder/last_appraiser_id"+feeid;
                 window.location.href(url);*/
                //location.reload();
                getOrderAppraiserDetails(feeid); //

            }

        });
    }).trigger('click');
    });

function getOrderAppraiserDetails(id)
{
    if(id!='' && id>0)
    {
        $.ajax({
            type: "GET",
            url: baseurl+"dashboard/orderappraiserdetails",
            data: 'app_id='+id,
            success: function(data)
            {
                //alert(data);
                //return false;
                //var currentIndex=$("input[name^=app_client_id]").length;
               //alert(data['user_id']);
                $('#app_details').html(data);

            }
        });

    }

}

when i click on Save action the replace values didn't get in POST.My form action will redirect to addorder action. In action

if($this->input->post())
    {
        print_r($this->input->post());
exit;

// Here i am not getting the order_assignment_appraiser name and value }

please suggest how to solve this issue. Thanks in advance.

I don't have enough reputation to comment, so I guess I will just do that here. I think we need more information:

  • How does the AJAX call get made? Is it on page load? Some more of the Javascript code surrounding that would be beneficial.

Besides that, I don't think this is the right pattern/solution for this problem. It looks like you have all the information already available to you, why not just load it into the form when the page loads using PHP? If you need clarification on how that would work, let me know. I think it would be straightforward enough for you to figure out, though.

I think there is an additional error in this code. You will replace the inner contents of the div#app_details with an identical copy of itself. So there will be a div#app_details div#app_details, like this:

<div class="input-group" id="app_details">
    <div class="input-group" id="app_details">
    <input type="text" class="form-control" name="order_assignment_appraiser" id= "order_assignment_appraiser" value="<?php echo $app_details['appraiser_first_name'].' '.$app_details['appraiser_last_name'];?>"> <?php echo form_error('order_assignment_appraiser');?>
    <input type="hidden" id="order_assignment_appraiser_id" name="order_assignment_appraiser_id" value=<?php echo $app_details['user_id'];?>>   
    <span class="input-group-btn">
    <a class="btn btn-default" id='addappr' href="<?php echo base_url('addappraiser?formtype=new')?>"><i class="fa fa-plus-square"></i></a>
     </span></div>
</div>

While this may not be directly causing the error, it won't help anything. If you really need to go with the AJAX approach to this, remove the outer div (with id app_details) from the appraiserdetailsajax file.