SHOW:
|
|
- or go back to the newest paste.
| 1 | <script> | |
| 2 | function getLikes() {
| |
| 3 | $.ajax({
| |
| 4 | - | url: "get_like.php"; |
| 4 | + | url: "get_like.php", |
| 5 | - | method: "post"; |
| 5 | + | method: "post", |
| 6 | - | data: {"get" : "likes"};
|
| 6 | + | data: {"get" : "likes"},
|
| 7 | - | dataType: "json"; |
| 7 | + | dataType: "json", |
| 8 | success: function(data){
| |
| 9 | $(data).each(function(k, v) {
| |
| 10 | $('[data-id='+v.post_id+']').find('span').text(v.likes);
| |
| 11 | }); | |
| 12 | } | |
| 13 | }); | |
| 14 | } | |
| 15 | ||
| 16 | function addLike(post_id) {
| |
| 17 | $.ajax({
| |
| 18 | - | url: "add_like.php"; |
| 18 | + | url: "add_like.php", |
| 19 | - | method: "post"; |
| 19 | + | method: "post", |
| 20 | - | data: {"add" : post_id};
|
| 20 | + | data: {"add" : post_id},
|
| 21 | - | dataType: "json"; |
| 21 | + | dataType: "json", |
| 22 | success: function(data){
| |
| 23 | if (data == 'success') {
| |
| 24 | getLikes(); | |
| 25 | } | |
| 26 | } | |
| 27 | } | |
| 28 | ||
| 29 | function unLike(post_id) {
| |
| 30 | $.ajax({
| |
| 31 | - | url: "add_like.php"; |
| 31 | + | url: "add_like.php", |
| 32 | - | method: "post"; |
| 32 | + | method: "post", |
| 33 | - | data: {"remove : post_id};
|
| 33 | + | data: {"remove : post_id},
|
| 34 | - | dataType: "json"; |
| 34 | + | dataType: "json", |
| 35 | success: function(data){
| |
| 36 | if (data == 'success') {
| |
| 37 | getLikes(); | |
| 38 | } | |
| 39 | } | |
| 40 | } | |
| 41 | ||
| 42 | setInterval(function (){
| |
| 43 | getLikes(); | |
| 44 | }, 1000); | |
| 45 | ||
| 46 | $('#add_like_button').on('click', function(){
| |
| 47 | var post_id = $(this).closest('.post').data('id');
| |
| 48 | addLike(post_id); | |
| 49 | }) | |
| 50 | ||
| 51 | $('#remove_like_button').on('click', function(){
| |
| 52 | var post_id = $(this).closest('.post').data('id');
| |
| 53 | unLike(post_id); | |
| 54 | }) | |
| 55 | </script> |