我想在带有Ajax的文本框中显示ID

时间:2018-11-06 06:44:56

标签: php jquery mysql sql

查看页面:

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

1

2 个答案:

答案 0 :(得分:0)

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

尝试这样

form_with

remote

答案 1 :(得分: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);
}