I've created a like button for my users posts. I'm trying to print out the amount of likes. At the moment when I click the LIKE button nothing shows beside the like button unless I refresh the page then it shows the amount of like clicks the post has (4).
The problem I face is I have a LIKE_DO.php page that collects the data then sends it to a function which is in another page called function_user.php. Is there anyway I can use Ajax to grab the printed value of likes and how would I go about it? I would really like to just build ontop of the ajax I already have, to insert the data and make a call for the printed likes to save confusion and having to re-write all my code again.
Like Button
echo "<div class='stream_option'><a id='likecontext_".$streamitem_data['streamitem_id']."' style='cursor:pointer;' onClick=\"likestatus(".$streamitem_data['streamitem_id'].",this.id);\">";
CURRENT AJAX
function likestatus(postid,contextid){
var obj = document.getElementById(contextid);
if(obj.innerHTML=="Like"){
obj.innerHTML="Unlike";
}else{
obj.innerHTML="Like";
}
$.post("../include/like_do.php", { streamitem_id: postid} );
}
LIKE_DO.PHP
<?php
session_start();
require"rawfeeds_load.php";
if(isset($_POST['streamitem_id'])){
$check = user_core::check_liked($_SESSION['id'],$_POST['streamitem_id'],1);
user_core::do_like($_SESSION['id'],$_POST['streamitem_id'],1);
if($check==0){?>
<?php }else{ ?>
<?php }
}else{
echo "<script>alert('Error liking post');</script>";
}
?>
USER_CORE - (With my printed likes that I need to get with ajax)
function print_like_count($streamid){
$check = "SELECT feedback_id FROM streamdata_feedback WHERE feedback_streamid='$streamid' AND feedback_rating=1";
$check1 = mysql_query($check);
$check2 = mysql_num_rows($check1);
if($check2>0){
return "(".$check2.")";
}
}