我想在带有ajax的文本框中显示id

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

查看页面:

<label >Challan No.</label>
<input type="text" class="form-control" id="dispach_challan_no"  name="dispach_challan_no" placeholder="Enter Challan No">

 <script>
    $.ajax({
            url :"<?php echo base_url();>booking/dispatch_challan/DispatchChallanController/fetchId",
            type:"GET",
            dataType: "html",
            success: function(data){

              $('#dispach_challan_no').html(data);

            },
            error:function(data){
              alert("error message"+data);
            },async:false,
          });    
  </script>

型号页面:

  public function fetchId(){
                 $query= $this->db->select('*')->from('bilty')->get();                  
                return $query->result_array();
}         

调节器

public function fetchId()
{
 $modelResult = $this->dispatchModel->fetchId();
}           

php jquery mysql sql
2个回答
0
投票

请用这个 -

查看页面 -

<label >Challan No.</label>
<input type="text" class="form-control" id="dispach_challan_no"  name="dispach_challan_no" placeholder="Enter Challan No">

 <script>
    $.ajax({
            url :"<?php echo base_url();>booking/dispatch_challan/DispatchChallanController/fetchId",
            type:"GET",
            dataType: "JSON",
            success: function(data){

              $('#dispach_challan_no').val(data[0]['id']);

            },
            error:function(data){
              alert("error message"+data);
            },async:false,
          });    
  </script>

型号 -

    public function fetchId(){
                 $query= $this->db->select('*')->from('bilty')->get();                  
                return $query->result_array();
}     

控制器 -

public function fetchId()
{
 $modelResult = $this->dispatchModel->fetchId();
 echo json_encode($modelResult);
} 

0
投票

只需从您的回复中获取ID即可。

试试这样

 success: function(data){
       var result =  data;
          $('#dispach_challan_no').html(result.id);

        },

要么

   success: function(data){
           var result =  data;
              $('#dispach_challan_no').html(result['id']);

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