我的数据库中有几条记录以HTML格式显示。
<?php foreach($adverts_list as $ad) { ?>
<!--anuncio 1-->
<div class="card all ad-isotope <?php echo $ad->ad_categorie; ?>">
<div class="card-body">
<div class="card-title">
<div class="card-info">
<i class="fa fa-tags"></i>
<p class="card-tag"><?php echo $ad->categorie_name; ?></p>
<?php if($ad->subCategorie_id != 10) { ?>
<p class="card-subcat"> <?php echo $ad->subCategorie_display; ?></p>
<?php } ?>
</div>
</div>
<div class="new-symbol">
<p>
<?php if($ad->ad_nouveau == 1) {
echo "nouveau";
} ?>
</p>
</div>
<div class="card-subtitle">
<p class="db-title"><?php echo $ad->ad_title; ?></p>
<p class="db-subtitle"><?php echo $ad->ad_subtitle; ?></p>
</div>
<div class="card-readmore">
<a data-toggle="modal" href="#ad-detail-modal-<?php echo $ad->ad_id; ?>">
<p class="read-more">voir l'annonce</p>
</a>
</div>
</div>
</div>
但是我不会根据单击按钮来过滤它。我将有10个按钮,每个按钮对应一个类别。我不想从按钮中提取innerHTML,并将其与具有相同类别的记录匹配。 我被困在这里
//save in variable all elements refering to categories
var categorias = document.querySelectorAll("a.link");
//a loop to create event on click of each element
for(var i = 0; i < categorias.length; i++) {
categorias[i].addEventListener("click", function() {
//save innerHTML
var categoria = this.innerHTML;
//make ajax call
$.ajax({
url: "index.php",
type: "GET",
dataType: "html",
success: function(response) {
}
});
});
}
如何进行ajax调用以搜索具有已保存类别的记录,并仅显示那些记录?