【发布时间】: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