所以我首先要说的是,我可能错过了一些明显的东西,但我真的无法弄清楚这一点。
我有一个过滤器,传递给ajax,将数据放入我刚刚创建的div
容器中。当我点击过滤器时,它会抓取数据并将其放入alert
但不会放入我创建的div
标记中
ajax电话:
$('.sponsorFilter').click(function(){
var id = $(this).attr('data-id');
var action = 'sponsorsfilter';
$.ajax({
url: "Sponsors/action.sponsors.php",
type: "POST",
data:{ action:action, id:id },
success: function(data){
alert(data);
$('.sponsorOutput').html(data);
},
error(jqXHR, textStatus, errorThrown){
alert(errorThrown);
}
});
});
HTML:
<div id="options" class="clearfix">
<ul id="filters" class="pagination option-set clearfix" data-option-key="filter">
<li><a class="sponsorFilter" href="#filter" data-option-value="*" class="selected">Show all</a></li>
<li><a class="sponsorFilter" href="#filter" data-id="Saddlery" data-option-value=".Saddlery">Saddlery</a></li>
<li><a class="sponsorFilter" href="#filter" data-id="Animals" data-option-value=".Animals ">Animals and Pets</a></li>
<li><a class="sponsorFilter" href="#filter" data-id="Automotive" data-option-value=".Automotive">Automotive</a></li>
<li><a class="sponsorFilter" href="#filter" data-id="Beauty" data-option-value=".Beauty">Beauty</a></li>
<li><a class="sponsorFilter" href="#filter" data-id="Services" data-option-value=".Services">Services</a></li>
<li><a class="sponsorFilter" href="#filter" data-id="Sports" data-option-value=".Sports">sports</a></li>
</ul>
</div><!-- #options -->
<div class="containerExtra">
<div id="container" class="clearfix">
<div class="sponsorOutput">
<?php
$getSponsors = getSponsors($page);
while($row = $getSponsors->fetch()){
?>
<div class="element transition <?php echo $row['FilterName']; ?>" data-category="transition">
<a href="<?php echo $row['SponsorWeb']; ?>" class="thumb"><figure class="img-polaroid"><img src="<?php echo $row['SponsorLogo']; ?>" alt="" height="200" width="200"></figure></a><span class="description"><?php echo $row['SponsorName']; ?></span>
</div>
<?php } ?>
</div>
<?php
if(isset ($_SESSION['userid']))
{
?>
<!-- <form action='sponsor.php' method='post' id='sponsors-form'> -->
<?php echo $row['SponsorPhone']; ?><br>
<?php echo $row['SponsorComments']; ?><br>
<input class='myButton' onClick="location.href='sponsors.php?SponsorID=<?php echo $row['SponsorID']; ?>'" type='submit' name='btnDelete' value='Delete'>
<input class='myButton' onClick="location.href='Sponsors/SponsorEdit.php?SponsorID=<?php echo $row['SponsorID']; ?>'" type='submit' name='btnDelete' value='Edit'>
<!-- </form> -->
<?php
}
?>
</div>
</div>
提前谢谢