Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- function getLikes() {
- $.ajax({
- url: "get_like.php",
- method: "post",
- data: {"get" : "likes"},
- dataType: "json",
- success: function(data){
- $(data).each(function(k, v) {
- $('[data-id='+v.post_id+']').find('span').text(v.likes);
- });
- }
- });
- }
- function addLike(post_id) {
- $.ajax({
- url: "add_like.php",
- method: "post",
- data: {"add" : post_id},
- dataType: "json",
- success: function(data){
- if (data == 'success') {
- getLikes();
- }
- }
- }
- function unLike(post_id) {
- $.ajax({
- url: "add_like.php",
- method: "post",
- data: {"remove : post_id},
- dataType: "json",
- success: function(data){
- if (data == 'success') {
- getLikes();
- }
- }
- }
- setInterval(function (){
- getLikes();
- }, 1000);
- $('#add_like_button').on('click', function(){
- var post_id = $(this).closest('.post').data('id');
- addLike(post_id);
- })
- $('#remove_like_button').on('click', function(){
- var post_id = $(this).closest('.post').data('id');
- unLike(post_id);
- })
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement