簡體   English   中英

Codeigniter-Ajax我需要返回多個行以及如何在我的視圖文件中訪問它

[英]Codeigniter-Ajax i need to return more than one rows and how to access it in my view file

當我在“購買清單”中單擊“發票編號”時,我將需要打開一個可折疊表格,該表格將列出與發票匹配的產品列表,否,我正在使用jquery打開可折疊表格,並使用Ajax來檢索數據

我的查看文件:我正在使用AJAX檢索數據

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

  }

return $row; 循環內部將僅返回一行。

代替:

foreach ($query->result() as $row)
{
    return $row;
}

做就是了:

return $query->result();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM