2019-03-28 10:44
浏览 514


I am creating ecommerce site by php. In my home page when anyone click any category (like mobile) in shop page i wanna show those category wise product by getting the category id in shop page url. I wanna make this by using ajax and also when click any brand (like samsung) checkbox in shop page brand wise product will auto load by ajax.

I am able to show brand wise product when checkbox checked but i can't show category wise product because dont know how to pass category id by ajax and catch the id on shop page

I have tried this way

In shop page Ajax call

<script type="text/javascript">

$(document).ready(function() {
    function filter_data()
        $('.filter_data').html('<div id="loading"style=""></div>');
        var action='action';
        var brand=get_filter('brand');
        var id = <?php echo $_GET['id']; ?>; // get id from page url
            url: 'action.php',
            type: 'POST',
            data: {action: action,brand: brand,id: id},
//load by check the checkbox
    function get_filter(class_name) {
        var filter=[];
        $('.'+class_name+':checked').each(function() {
        return filter;
    $('.common_selector').click(function() {

show category and brand wise product

if (isset($_POST["action"])) {
    $query="select * from product where cat=id "; // selecting category wise product by id which was sent from ajax but faild 
if (isset($_POST["brand"])) {
    $brand_filter = implode(',',$_POST['brand']);
    $query="select * from product where brand IN ('$brand_filter')";
    $count =mysqli_num_rows($dbquery);
    $output = '';
    if ($count > 0) {
        while ($bf=mysqli_fetch_assoc($dbquery))
            $output.='<div class="col-md-3 ">
                        <div class="product">
                         <img src="img/'. $bf['image'] .'" class="img-responsive" >
                            <p class="Price"><b>Price:</b>'.$bf["price"].' </p>
                            <a href="details.php?id='.$bf['id'].'" class="btn btn-success">
                              <button id="product" pid='.$bf["id"].' class="btn btn-primary">
                                <span class="glyphicon glyphicon-shopping-cart"></span> Add Cart

    } else {
        $output = '<h3>No Data Found</h3>';
    echo $output;

Since 6 month i am stuck on this project, if its solve then user side will be complete, So I humbly request for your help ....

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题