How could I make the votes update directly? Just like the votes on this site
I have this function:
function ratePost(id, rating) {
$.post("ratepost.php", {postID: id, rating: rating}, function(data){alert(data+" return val"); });
}
<span class="karma"><?php echo $rating ?></span>
i think you need to do 2 things in order for it to work:
<span id = 'rating'...></span>
function(data){document.getElementById("rating").innerHTML = data;}
Seems you are with a javascript library like jQuery.
So you can target your span like that in your callback :
function(data){ $(".karma").html(data) }
Here it is what you want (I think :-)) :
function ratePost(id, rating) {
$.post("ratepost.php", {postID: id, rating: rating}, function(data){
var current = $(".karma").html();
$(".karma").html( current + 1 );
});
}
<span class="karma"><?php echo $rating ?></span>