【问题标题】:get data dynamically in select tag in CodeIgniter在 CodeIgniter 的选择标签中动态获取数据
【发布时间】:2021-08-29 13:13:50
【问题描述】:

下面是我的代码,它不起作用。我想从数据库中动态获取选择标签中的数据列表。但数据未显示在列表中。它是空白的。请帮帮我

观看次数

              <'<thead>
                 <tr>
                    <th>No.</th>
                    <th>Products</th>
                    <th style="width: 31%">Qty</th>
                    <th>Price</th>
                 </tr>
              </thead>
              <tbody>
                 <tr>
                    <td scope="row">1</td>
                    <td style="width:60%">
                <form method="POST">
                       <select name="products" id="products"   class="form-control">
                          
                         <option value=""></option>

                       </select>'>

控制器

      <' public function getproducts(){

   $id=$_POST['product_name'];
   $mydata['products']=$this->lg->select_product($id);
   echo json_encode($mydata);
}

'>

模型

     <' public function select_product($id){

 $r= $this->db->select('*')->from('products')->WHERE('id',$id)->get();
 $rs=$r->result_array();
 return $rs;
             }           

'>

js

        <'$(document).ready(function(){
         $('#products').change(function() {
          var id = $(this).find(':selected')[0].id;
         $.ajax({
                type:'POST',
               url:'<?php echo FORMURL;?>Adminlogin/getproducts',
               data:{id : id},
               dataType:'json',
               success:function(data)
         {
           $('#price').text(data.product_price);

           $('#qty').text(data.product_qty);
        }
   });
 });'>

【问题讨论】:

  • 花点时间阅读帮助中心的editing help。 Stack Overflow 上的格式化与其他站点上的不同。您的帖子看起来越好,其他人就越容易阅读和理解。
  • 请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。

标签: php codeigniter selection


【解决方案1】:

删除数据类型 JSON

public function getproducts(){
   $id = $this -> input -> post('id');
   $mydata['products']=$this->lg->select_product($id);
   echo json_encode($mydata);
}

【讨论】:

  • 但我不必将此表单发送到任何地方,我只想在选择标签中获取数据
  • 在哪里,在控制器中
猜你喜欢
  • 2013-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-21
  • 2019-03-31
  • 2021-07-28
  • 1970-01-01
  • 2017-05-04
相关资源
最近更新 更多