Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

display eror on voting button like stack overflow

I am not getting any error and also this is not working the way I want it to be. I have a jQuery upvote plugin in my project. To avoid span I am validating user input on every vote. Everything is working and I am getting the error If I try to span the voting functionality from my php file. The problem is when I try to show that message on the screen just like stack overflow.

Currently I have this but the out is not what I wanted:

 <script>
var callback = function(data) {

$.ajax({
    url: 'voting.php',
    type: 'post',
    data: { id: data.id, up: data.upvoted, down: data.downvoted, star: data.starred },
    success: function(result) {  
    $("[data-id='" + data.id + "']").html(result);
} 
});
};
 $('.upvote').upvote({callback: callback});

</script>

Output where the error replaces the up and down vote :

enter image description here

My html which has a span tag but not sure how to use it?

  if($RES['counter'] === '1'){
 echo '
         <td>
           <div  data-id='.$id.' class="upvote upvote-serverfault">
            <a style="cursor:pointer;" class="upvote upvote-on" title="This idea is helpful"></a>
            <span class="count">'.$counter.'</span>
            <a class="downvote"></a>
            <span class="votingFeedback"></span>
          </div>
      </td>';  
    }
    else 
        if($RES['counter'] === '-1'){
    echo '
      <td>
        <div  data-id='.$id.' class="upvote upvote-serverfault">
            <a style="cursor:pointer;" class="upvote upvote-down" title="This idea is helpful"></a>
            <span class="count">'.$counter.'</span>
            <a class="downvote downvote-on"></a>
            <span class="votingFeedback"></span>  
        </div>
      </td>';
    }
like image 291
sach jot Avatar asked Jun 13 '26 00:06

sach jot


1 Answers

$.ajax({
    url: 'voting.php',
    type: 'post',
    data: { id: data.id, up: data.upvoted, down: data.downvoted, star: data.starred },
    success: function(result) {  
    $("[data-id='" + data.id + "']").find("span.votingFeedback").text(result);
} 
});

Using this you can show the error in the respective span element with class votingFeedback.

like image 119
SRK Avatar answered Jun 15 '26 13:06

SRK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!