Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript isNan在jQuery中使用此选择器和动态内容_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript isNan在jQuery中使用此选择器和动态内容

Javascript isNan在jQuery中使用此选择器和动态内容,javascript,jquery,ajax,Javascript,Jquery,Ajax,这是我尝试使用的函数 $('body').on('click', '.up-vote', function(event) { event.preventDefault(); var data = {"action": "voteKarma", "id": $(this).data("id"), "value": $(this).data("val")} $.post(window.apiURL, data, function(result) { switc

这是我尝试使用的函数

$('body').on('click', '.up-vote', function(event) {
    event.preventDefault();
    var data = {"action": "voteKarma", "id": $(this).data("id"), "value": $(this).data("val")}
    $.post(window.apiURL, data, function(result) {
        switch(result['status']) {
            case 1:
                var vote_sum_text = $(this).next(".sum").text();
                if (!isNaN(parseInt(vote_sum_text, 10))) {
                    var vote_sum_text = $(this).next(".sum").text();
                } else { alert("isNaN Variable") } 
            break;
    }, 'json');
});
当Ajax结果返回0时,它返回一个带有isNaN变量的警报,这是我调试问题的备用方法

这是我的HTML布局,它是使用另一个Ajax请求动态捕获的。
  • 格式中列出了多个div:

    <div class="votes pull-left">
        <a class="up-vote" href="#" data-id="20" data-val="1"><span class="fa fa-arrow-circle-o-up"></span></a>
        <span class="sum" style="font-weight:400;color:#666;">
             0
        </span>
        <a class="down-vote" href="#" data-id="20" data-val="0"><span class="fa fa-arrow-circle-o-down"></span></a>
    </div> 
    
    
    0
    
    简而言之,;当您单击
    .up vote
    down vote
    时,它将发送一个AJAX请求,然后获取
    .sum
    值的
    文本()

    $(event.currentTarget).next(".sum").text();
    

    因为
    .post
    中的
    不涉及元素

    ,所以您也可以使用以下内容:

    $('body').on('click', '.up-vote', function(event) {
       event.preventDefault();
       var up_vote_this = $(this);
       ....
       ....
       //now you can use the variable in the success function...
    
          var vote_sum_text = up_vote_this.next(".sum").text();