【问题标题】:i want to show id in text box with ajax我想用ajax在文本框中显示id
【发布时间】:2018-11-06 06:44:55
【问题描述】:

查看页面:

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

【问题讨论】:

  • 你有什么错误吗?
  • 不知道你到底卡在哪里了?
  • $('#dispach_challan_no').val(data);

标签: php jquery mysql sql


【解决方案1】:

请使用这个 --

查看页面 -

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-24
      • 1970-01-01
      • 2012-10-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多