2015-11-08 33 views
0

我有三個視圖文件夾視圖和我想用Ajax調用通過點擊鏈接中的按鈕來顯示類別表和產品表... input.php同時顯示錶中的數據負載表調用笨

<div class="wrapper"> 
    <div class="container"> 
     <div class="jumbotron"> 
     <h1>View Two Records By Click Event</h1> 
     </div> 

    <div id="show-catg"> 
     <?php $this->load->view('show'); ?> 
    </div> 

    <div id="show-prd"> 
     <?php $this->load->view('show_pro'); ?> 
    </div> 

,但我想這顯示使用單擊事件..喜歡

<a href="" class="show_catg">Categories</a> 
<a href="" class="show_prd">Product</a> 
$('.show_catg').click(function(){ 
    url:, 
    data:, 
}); 
$('.show_prd').click(function(){ 
    url: 
    data: 
}); 

這是5月控制器類功能

public function index(){ 
    $data= $this->Model_data->getAll_categories(); 
    $data1 = $this->Model_data->getAll_product(); 
    $Dataa = array('categories' => $data,"products"=>$data1); 
    $this->load->view('input',$Dataa); 

    } 

Model_data類

function getAll_categories(){ 
    $this->db->select('*'); 
    $this->db->from('categories'); 
    $this->db->limit(50); 
    $this->db->order_by('Catg_ID','ASC'); 
    $query = $this->db->get(); 

    return $query->result(); 
    } 
public function getAll_product(){ 
    $this->db->select('*'); 
    $this->db->from('product'); 
    $this->db->limit(50); 
    $this->db->order_by('Prod_ID','ASC'); 
    $query = $this->db->get(); 

    return $query->result(); 
    } 
+0

沒事做類似的方式..但真的需要幫助....:| – Khushi

回答

0

首先呼叫getAll_categories()在一種不同的方法。像

Xyz.php文件(控制器)

public function get_cat(){ 
    $data = $this->Model_data->getAll_categories(); 
    $html = ''; 
    foreach($data as $d){ 
    $html .= '<li>'.$d['cat_name'].'</li>'; 
    } 
echo $html; 
} 

jQuery代碼

$('.show_catg').click(function(){ 
    url: site_url('xyz/get_cat'), 
    type:'post', 
    dataType: 'html', 
    success: function (response) { 
     $('#suggestion').show().html(response); 
    }, 
}); 

getAll_product()方法

+0

先生,我沒有得到如何打電話可能通過ajax查看數據,是的,我已經這樣做....正如我所提到的,我創建了3個視圖文件,其中1個文件從數據庫中獲取記錄,但事情是我沒有得到我怎麼能通過ajax這是在一個單獨的文件中調用我的視圖分類文件....這是我的分類視圖 <?php foreach($ categories as $ row){ echo「「; echo「​​$ row-> Catg_ID」; echo「​​$ row-> Catg_Name」; echo「」; } ?> – Khushi