控制器:
因为我使用了两个表类和secound sub_category 在类别I中,我获取了要动态显示的类别名称 在Sub_Category中我获取了图片,价格,标题
public function product_grid()
{
$id= $this->input->post('dataid');
echo 'Data-Id is form controller: '.$id ;
$this->PizzaUp_User_model->getid($id);
$data['res'] = $this->PizzaUp_User_model->select('category');
$data['rs'] = $this->PizzaUp_User_model->get_cetegory('sub_category');
$this->load->view('product_grid',$data);
}
查看档案
<?php
foreach ($res as $ro)
{
?>
<div data-filter="<?php echo $ro['category_id']; ?>" data_id="<?php echo $ro['category_id']; ?>" name="id" class="cbp-filter-item button_id">
<?php echo $ro['category_name']; ?><div class="cbp-filter-counter"></div>
</div>
<?php
}
?>
</div>
<div id="grid-container" class="cbp" >
<?php foreach ($rs as $row)
{
?>
<div class="cbp-item <?php echo $ro['category_id']; ?>">
<div class="cbp-caption">
<div class="cbp-caption-defaultWrap">
<img src="<?php echo base_url('image/category/'.$row['image']); ?>" alt="">
</div>
<div class="cbp-caption-activeWrap">
<div class="cbp-l-caption-alignCenter">
<div class="cbp-l-caption-body">
<a href="more_get_id/<?php echo $row['sub_category_id'];?>" class="cbp-singlePage cbp-l-caption-buttonLeft">Add to cart</a>
<a href="<?php echo base_url('image/category/'.$row['image']); ?>" class="cbp-lightbox cbp-l-caption-buttonRight">view larger</a>
</div>
</div>
</div>
</div>
<div class="cbp-l-grid-projects-title"><?php echo $row['category_name']; ?></div>
<div class="cbp-l-grid-projects-desc"><?php echo $row['sub_category_title']; ?></div>
<div class="cbp-l-grid-projects-price"><?php echo $row['R_price']; ?></div>
</div>
<?php
}
?>
使用Ajax获取并传递id
<script type="text/javascript">
$(document).ready(function() {
$(".button_id").click(function(){
var dataid=$(this).attr('data_id');
$.ajax({
url: '<?php echo site_url(); ?>/Home/product_grid',
type: "POST",
data: {
dataid: dataid
},
success: function(data) {
alert(data);
},
error: function(xhr, status, error) {
var error=xhr.responseText;
alert(error);
}
});
});
});
</script>
答案 0 :(得分:1)
我不知道php,但猜测你的控制器功能缺少参数
public function product_grid()
到
public function product_grid($dataid)