Php Codeigniter Ajax我需要返回多行,以及如何在视图文件中访问它
当我点击“采购清单”中的“发票号”时,我需要打开一个可折叠的表格,列出与发票号匹配的产品清单 我使用jquery打开一个可折叠的表,使用Ajax检索数据 我的视图文件:我正在使用AJAX检索数据Php Codeigniter Ajax我需要返回多行,以及如何在视图文件中访问它,php,ajax,codeigniter,Php,Ajax,Codeigniter,当我点击“采购清单”中的“发票号”时,我需要打开一个可折叠的表格,列出与发票号匹配的产品清单 我使用jquery打开一个可折叠的表,使用Ajax检索数据 我的视图文件:我正在使用AJAX检索数据 <script> $(document).ready(function(){ $(".listproduct".click(function(){ var value = $(this).text(); $.ajax({ type:'POST', ur
<script>
$(document).ready(function(){
$(".listproduct".click(function(){
var value = $(this).text();
$.ajax({
type:'POST',
url:'<?=site_url("purchasecont/getproductlist"; ?>',
data: {'data' : value} ,
success:function(result){
$('#invoiceno').html(result['invoiceno']);
$('#productname').text(result['productname']);
$('#price').text(result['price']);
}
});
$(".collapse".collapse('toggle');
});
});
</script>
我的模型文件:我将从表中检索多行
public function getproductlist(){
//check if is an ajax request
if($this->input->is_ajax_request()){
//checks if the variable data exists on the posted data
if($this->input->post('data')){
//query in your model you should verify if the data passed is legit before querying
$data = $this->purchasemod->getproductlist($this->input->post('data'));
$this->output->set_content_type('application/json');
$this->output->set_output(json_encode($data));
return $data;
}
}
}
public function getproductlist($q){
$this->db->select('*');
$this->db->from('purchaseprolist');
$this->db->where('purchaseprolist.invoice' , $q);
$this->db->where('purchaseprolist.price != ',0,FALSE);
$query = $this->db->get();
foreach ($query->result() as $row)
{
return $row;
}
}
返回$row循环内部的代码>将只返回一行
而不是:
foreach ($query->result() as $row)
{
return $row;
}
只要做:
return $query->result();
请帮帮我!我有一个错误