2015-11-08 55 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