AJAX+;PHP投票系统
我正在用AJAX和PHP开发一个投票系统,遇到了一些麻烦。我们正在显示数据库中的一组帖子,每一篇帖子旁边都有一张图片——点击图片应该是1)切换图片颜色,然后2)使用AJAX调用PHP脚本,然后决定是添加还是减少投票。我有图像切换工作,但我不知道如何做下一部分。最好的方法是什么 这是while循环,用于输出POST:AJAX+;PHP投票系统,php,javascript,ajax,voting,Php,Javascript,Ajax,Voting,我正在用AJAX和PHP开发一个投票系统,遇到了一些麻烦。我们正在显示数据库中的一组帖子,每一篇帖子旁边都有一张图片——点击图片应该是1)切换图片颜色,然后2)使用AJAX调用PHP脚本,然后决定是添加还是减少投票。我有图像切换工作,但我不知道如何做下一部分。最好的方法是什么 这是while循环,用于输出POST: while($row = mysql_fetch_array($result)) { ?> <li class = "p
while($row = mysql_fetch_array($result))
{
?>
<li class = "post">
<a href = "#" onclick = "return toggle(this,'heart<?php echo $row['post_id'];?>')"><img name = "heart<?php echo $row['post_id'];?>" src = "/images/heart.png" class = "thumbnail" width = "15" /></a>
<p class = "title"><img class = "favicon" width = "16" height = "16" src = "<? echo $row['favicon']; ?>" /><a href = "<? echo $row['post_url']; ?>" target = "_blank"><? echo $row['post_title']; ?></a></p>
<p class = "postinfo">posted <? echo doRelativeDate( $row['date'] ); ?> by <a href = "<? echo $row['blog_url'];?>"><? echo $row['blog_name']; ?></a>
</li>
<?
}
?>
while($row=mysql\u fetch\u array($result))
{
?>
“/>
发布人
“src=“/images/heart.png”class=“thumbnail”width=“15”id=“voteImage
/>
向图像添加一个ID。通过任何javascript框架捕获此ID上的单击事件
我在jQuery中给出了一个例子
jQuery("#voteImage").live("click",function(){
var imageName = jQuery(this).attr('name');
var postId = imageName.substr(5); //Here you will have post Id because remove heart from heart20
//now you can hit ajax call to your vote-up or vote-Down php with postId
jQuery.ajax({
type: 'POST',
url: baseURI+'voteup.php',
data:"postId="+postId,
cache: false,
success: function(result)
{
//perform further action like give alert to user that action performed
}
});
}
谢谢你的回复。我想我应该说得更清楚:我需要帮助编写AJAX,这将允许我对帖子进行投票。