使用codeigniter和ajax搜索一个id并将该id对应的数据放置在同一页面中。数据无法放置到字段中

问题描述 投票:0回答:1

正在获取id对应的数据,但无法放入文本字段。 我想在文本字段中放置与该 id 相对应的数据。任何人都可以提供帮助。它没有得到 控制器

 public function addrfqoffline() {
        $this->load->helper(array('form', 'url'));
        $this->load->view('moderator/templates/header');
        $this->load->view('moderator/templates/sidebar');
        $rid=$this->input->post('reqid');
         echo $rid;
      $requirement=$this->requirement_model->viewdata($rid);
      $data['customers']=$this->userdata->usersname();
        $data['merchants']=$this->merchant_model->merchantname();
       // $data['mroproducts']=$this->mroproduct_model->mroproductname();
        $data['units']=$this->requirement_model->fetchunits();

        if($requirement)
      {
           foreach ($requirement as $reqdata) {
                $dat['reqid'] = $reqdata->rqm_id;
                $dat['service'] = $reqdata->rqm_service;
               $this->load->view('moderator/mrorfqnew',array_merge($dat,$data));
           }

      }
        $this->load->view('moderator/mrorfq',$data);
            $this->load->view('moderator/templates/footer');
}

查看

   <div class="col-xs-6">
        <label for="txtname">Title of Quotation Request :</label>
        <input type="text" name="txtTitle" class="form-control" id="txtname"  value="<?php if(!empty($reqid)){echo $reqid;} ?>" required>
   </div>`enter code here`

型号

public function viewdata($reqid) {
      $this->db -> select('*');
        $this -> db -> from('jil_requirements');
    $this -> db -> where('rqm_id',$reqid);
    $query = $this -> db -> get();
         return $query->result();
}

ajax

<script>
function getValue(val) {
  //alert(val);
    $.ajax({
    type: "POST",
    url: "<?php echo base_url()?>moderator/RFQ/addrfqoffline",
    data:'reqid='+val,
    success: function(data){
             alert(data);
        $("#txtproduct").html(data);
    }
    });
}
</script>
php ajax codeigniter codeigniter-3 codeigniter-2
1个回答
1
投票

首先在要显示内容的页面中创建一个空的div。

 <div id="content"></div>

接下来,像这样更改控制器功能

function addrfqoffline() {
    $content = "";
    $this->load->helper(array('form', 'url'));
    $content = $this->load->view('moderator/templates/header','',true);
    $content .= $this->load->view('moderator/templates/sidebar','',true);
    $rid = $this->input->post('reqid');        
    $requirement = $this->requirement_model->viewdata($rid);
    $data['customers'] = $this->userdata->usersname();
    $data['merchants'] = $this->merchant_model->merchantname();
    // $data['mroproducts']=$this->mroproduct_model->mroproductname();
    $data['units'] = $this->requirement_model->fetchunits();

    if ($requirement) {
        foreach ($requirement as $reqdata) {
            $dat['reqid'] = $reqdata->rqm_id;
            $dat['service'] = $reqdata->rqm_service;
            $content .= $this->load->view('moderator/mrorfqnew', array_merge($dat, $data),true);
        }
    }
    $content .= $this->load->view('moderator/mrorfq', $data,true);
    $content .= $this->load->view('moderator/templates/footer',true);
    echo $content;// this will echo the view here
}

现在ajax成功了,

success: function(data){
    $("#content").html(data);
}

这应该对你有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.