1

I want to display like count for that post the user likes, every post like href has a specific id, now if I am clicking the post having id 222. Then like count having id 222 will refresh.

<a href="" onclick="rate('111');">like</a> <div id="111">4</div>
<a href="" onclick="rate('222');">like</a> <div id="222">5</div>
<a href="" onclick="rate('333');">like</a> <div id="333">12</div>

My rate function

<script type="text/javascript">
function rate(c) 
{   
        var c   
    jQuery.ajax({
        type: 'POST',
        url: 'rate.php',
        data: {
                cmnt: c     
               }
         });  
          return false; 
}
</script>

the C variable is getting the post id

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140

1 Answers1

0

you can update your rate() function as given below

<script type="text/javascript">
    function rate(c) 
    {   
        jQuery.ajax({
            type: 'POST',
            url: 'rate.php',
            data: {cmnt: c},
            success: function(html) {
                var count = $("#"+c).html();
                var new_count = parseInt(count)+parseInt(1)
                $("#"+c).html(new_count);
             }
             });  
              return false; 
    }
    </script>

let me know if that helped you...

Nishant Solanki
  • 2,119
  • 3
  • 19
  • 32
  • its working in some manner.. but not getting what i need.. after clicking like link its showing the text 'NAN' in the div in which like count is displayed.. – Priya Majumder Apr 17 '15 at 13:30
  • @PriyaMajumder I tried the code and its working absolutely fine.. can you show me what error you are getting? – Nishant Solanki Apr 27 '15 at 05:15