function vote_up(){
$("a.vote_up").click(function(){
the_id = $(this).attr('id');
$(this).parent().html("<img src='" + home + "/img/spinner.gif'/>");
$("span#votes_count"+the_id).fadeOut("fast");
$.ajax({
type: "POST",
data: "action=vote_up&id="+$(this).attr("id"),
url: home + "/ajax.php",
success: function(msg)
{
$("span#votes_count"+the_id).html(msg);
$("span#votes_count"+the_id).fadeIn();
$("span#vote_buttons"+the_id).remove();
},
error: function(msg) {
$.msgBox({ title: "Uyarı", content: 'Oylama Sırasında Hata Meydana Geldi!'});
}
});
});
}
function vote_down(){
$("a.vote_down").click(function(){
the_id = $(this).attr('id');
$(this).parent().html("<img src='" + home + "/img/spinner.gif'/>");
$.ajax({
type: "POST",
data: "action=vote_down&id="+$(this).attr("id"),
url: home + "/ajax.php",
success: function(msg)
{
$("span#votes_count"+the_id).fadeOut();
$("span#votes_count"+the_id).html(msg);
$("span#votes_count"+the_id).fadeIn();
$("span#vote_buttons"+the_id).remove();
},
error: function(msg) {
$.msgBox({ title: "Uyarı", content: 'Oylama Sırasında Hata Meydana Geldi!'});
}
});
});
}PHPif(isset($_POST["action"])){
$id = $_POST["id"];
$action = $_POST["action"];
$cur_votes = getAllVotes($id);
if($action=="vote_up")
{
$votes_up = $cur_votes[0]+1;
$q = "UPDATE comments SET votes_up = $votes_up WHERE id = $id";
}
elseif($action=="vote_down")
{
$votes_down = $cur_votes[1]+1;
$q = "UPDATE comments SET votes_down = $votes_down WHERE id = $id";
}
$r = mysql_query($q);
if($r)
{
$effectiveVote = getEffectiveVotes($id);
echo $effectiveVote." Oy";
}
elseif(!$r)
{
echo "Hata!";
}
}Bu kodda nerde hata var ?Jquery ilk tıklamama tetiklemiyor, ikinci tıklamaya tetikliyor.
O da şu sorunu yaratıyor.
Örneğin a makalesinin oylaması 18 olsun.
Ben bu makaleye olumsuz oylama vereceğim.
Verdiğim zaman jquery 2.kez tetiklediği için 16 oylamaya düşüyor.
Sorun nerede acep ?