dpict99695329 2018-04-17 21:10 采纳率: 100%
浏览 72
已采纳

跨越upvote插件时显示错误,如堆栈溢出

I have a jQuery up vote plugin. Everything is working fine except the error handling. My up vote plugin is in a foreach loop. like this below

  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 id='.$index.'><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 id='.$index.'><span class="votingFeedback"></span>  
            </div>
          </td>';
        }

The problem is when the user tries to span my voting system it will throw an error.The error checking is done in my PHP file and It's working but when I tries to dispaly the error on screen instead of showing the message on that particular topic is it shows on all the topic id

enter image description here

I was trying to make something like stack overflow. If you try to span the up or down vote it will throw and error but it's seems harder then I thought

My ajax call to my php file

<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(data) {      
        $(".votingFeedback").html(data);
    }
    });
};
$('.upvote').upvote({callback: callback});

 </script>
  • 写回答

2条回答 默认 最新

  • dongxu2398 2018-04-17 21:29
    关注

    You are getting unrecognized expression because you are replacing your original data variable with the new results from the ajax. from @allcutt answer try changing it to this.

    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 + "'] .votingFeedback").html(result);
        }
        });
    };
    $('.upvote').upvote({callback: callback});
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条