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条)

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题