简体   繁体   English

引导卡过滤 PHP/AJAX 问题

[英]Bootstrap Cards Filter PHP/AJAX Problems

I have a page of a website which has bootstrap cards on.我有一个网站页面,上面有引导卡。 The cards are generated dynamically, but I wanted to add a filter section.这些卡片是动态生成的,但我想添加一个过滤器部分。 I am trying to use AJAX to acheive this, I have got to a point where when you select a checkbox it triggers the loader gif but then that loader gif doesn't disapear.我正在尝试使用 AJAX 来实现这一点,我已经到了一个地步,当您使用 select 复选框时,它会触发加载程序 gif,但随后加载程序 gif 不会消失。 Through my hours of debugging I can see that its the page that the AJAX call is calling that is the problem, but I just can't see what the issue is and I am not getting errors or anything in the console.通过我数小时的调试,我可以看到它是 AJAX 调用所调用的页面,这是问题所在,但我只是看不出问题出在哪里,我在控制台中没有收到错误或任何内容。 If anyone has any ideas I would really appreciate it, I have pasted my code below, also I am aware my sql queries are currently open to injection, just want to get it to work first.如果有人有任何想法,我将不胜感激,我在下面粘贴了我的代码,我也知道我的 sql 查询目前可以注入,只想让它先工作。

<body>
<?php include("PHP/header.php"); ?>



<div class="container-fluid">


<div class="container" style="margin-top: 2%; text-align: center;"> 
<h1>Title goes here</h1>
Some tetx
<br/>
<br/>
<br/>

Filter Reviews:

<ul class="list-group">
<?php
$search = $conn->prepare("SELECT DISTINCT reviewcat FROM review_db ORDER BY reviewcat");
$search->execute(); 

while ($row = $search->fetch(PDO::FETCH_ASSOC)) {       
?>
<li class="list-group-item">
    <div class="form-check">
    <label class="form-check-label">
    <input type="checkbox" class="form-check-input product_check" value="<?=$row['reviewcat'];?>" id="reviewcat"> <?=$row['reviewcat']; ?>
    </label>
    </div>
</li>
<?php } ?>
</ul>

</div>
<br/><br/>  

<div class="row-fluid ">
    
    <h5 class="text-center" id="textChange"> All Products </h5>
    <hr>
    <div class="text-center">
        <img src="Images/loader.gif" id="loader" width="100" style="display: none">
    </div>
    
        
    
     <div id="result" class="card-deck card_group_style pt-4" >
         
     <?php

        
        $res_data = $conn->prepare("SELECT * FROM review_db");
        $res_data->execute();
        
    

       
    ?>
    
    <?php while ($row = $res_data->fetch(PDO::FETCH_ASSOC)) {// Important line !!! Check summary get row on array .. ?>
    

<div class="col-sm-6 col-lg-3 py-2">
    
<div class="card mb-4">
        
        
    
  <img class="card-img-top card-images " src="Images/Reviews/<?php echo $row['reviewimage1'];?>" alt="<?php echo $row['reviewtitle'];?>" >
  <div class="card-body">
    <h5 class="card-title"><?php echo $row['reviewtitle'];?></h5>
    <p class="card-text"><?php echo $row['reviewsynop'];?></p>
    

    
    <a href="Reviews/review-content.php?id=<?php echo $row['id'];?>&reviewtitle=<?php echo $row['reviewtitle'];?>" class="btn btn-primary my-4" >Read More</a>
    <div class="card-footer" style="padding: 1%;">
      <small class="text-muted">Submitted: <?php
          $my_date = $row['reviewsub'];
            $date = DATE("d/m/Y",strtotime($my_date));
            echo $date;?></small>
    </div>
  </div>
  
 
</div> 
</div>
    
    
    
    
    <?php } ?>
    
    
    
</div>



    
  
   


    </div>
    
</div>
<?php include("PHP/footer.php"); ?>

</div>

</body>

 <?php include("PHP/js.php"); ?>

<script>
$(document).ready(function(){
 $('#link-review,#link-footer-review').addClass('active');
});
</script>
<script type="text/javascript">
    $(document).ready(function(){
        
        function get_filter_text(text_id){
            var filterData = [];
            $('#'+text_id+':checked').each(function(){
                filterData.push($(this).val());
            });
            return filterData;
        }
        
        $(".product_check").click(function(){
            
            $("#loader").show();
            
            var action = 'data';
            var reviewcat = get_filter_text('reviewcat');
            
            $.ajax({
                method:'POST',
                url:'reviewaction.php',
                data:{action:action,reviewcat:reviewcat},
                success:function(response){
                    $("#result").html(response);
                    $("#loader").hide();
                    $("#textChange").text("Filtered Reviews");
                }
                
            });
            
        });
        
        
        
    });
</script>

</html>

reviewaction.php reviewaction.php

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
include_once $_SERVER['DOCUMENT_ROOT'] . '/Private/db.php';

// $stmt = $conn->prepare("SELECT * FROM blogdata ORDER BY blogsub DESC");
// $stmt->execute();
?>
<?php
    
    if(isset($_POST['action'])){
        
        $sql = "SELECT * FROM review_db WHERE reviewcat !=''";
        
        
        
        
        $revsearch = $conn->prepare($sql);
        $revsearch->execute();
        $output='';
        
        if($revsearch->num_rows>0){
            while ($row = $revsearch->fetch(PDO::FETCH_ASSOC)) {
                $output .= '
                <div class="col-sm-6 col-lg-3 py-2">
    
<div class="card mb-4">
        
        
    
  <img class="card-img-top card-images " src="Images/Reviews/'. echo $row['reviewimage1'];.'" alt="'. echo $row['reviewtitle'];.'" >
  <div class="card-body">
    <h5 class="card-title">'. echo $row['reviewtitle'];.'</h5>
    <p class="card-text">'. echo $row['reviewsynop'];.'</p>
    

    
    <a href="Reviews/review-content.php?id='. echo $row['id'];.'&reviewtitle='. echo $row['reviewtitle'];.'" class="btn btn-primary my-4" >Read More</a>
    <div class="card-footer" style="padding: 1%;">
      <small class="text-muted">Submitted: '.
          $my_date = $row['reviewsub'];
            $date = DATE("d/m/Y",strtotime($my_date));
            echo $date;.'</small>
    </div>
  </div>
  
 
</div> 
</div>
                
                
                
                
                ';
                
                }
                
        
        else{
            $output = "<h3>No Reviews Found!</h3>";
        }

        
        
        
        
        
                
    
    echo $output;
    } 


    
?>

I have actually found something in the server error log, I was stupidly only use dev tools on firefox, but have found that in the reviewaction.php script I had left semicolons in and had also missed a closing bracket.我实际上在服务器错误日志中发现了一些东西,我愚蠢地只在 firefox 上使用开发工具,但发现在 reviewaction.php 脚本中我留下了分号并且还错过了右括号。 There are still some other problems, which I can fix, just couldn't work out why it wasn't firing.还有一些其他问题,我可以解决,只是无法弄清楚为什么它没有触发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM