Pass response of AJAX only to current div among an array

前端 未结 2 1512
萌比男神i
萌比男神i 2021-01-28 05:19

I\'ve managed to make simple voting system with single current score. Everything is fine but the problem is that when I click on a button to vote for this particular

2条回答
  •  不要未来只要你来
    2021-01-28 05:47

    You haven't shown the code, but presumably the AJAX request is fired on click of a .vote element. If this is the case you can store a reference to the element which raised the event, then use DOM traversal to find the sibling .this and change it's HTML. Something like this:

    $('.vote').click(function(e) {
        e.preventDefault();
        var $vote = $(this); // store the element which raised the event here
        $.ajax({
            url: 'foo.php',
            success: function(html) {
                $vote.siblings('.this').html(html); // use siblings() to find .this to change
            }
        });
    });
    

提交回复
热议问题