我想用ajax在文本框中显示id

zf9nrax1  于 2021-06-18  发布在  Mysql
关注(0)|答案(2)|浏览(253)

查看页面:

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

szqfcxe2

szqfcxe21#

请用这个--
查看页面-

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

qaxu7uf22#

只需从您的响应中获取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']);

            },

相关问题