Reputation:
I have one question about my post like and unlike. The problem is when i click .like_button the <span id='you"+New_ID+"'><a href='#'>You</a> like this.</span>
not showing.
I still check with browser developers console. But when i click Like button Like button will changed but <span id='you"+New_ID+"'><a href='#'>You</a>, </span>
not showing. But if i refresh the page <span id='you"+New_ID+"'><a href='#'>You</a>, </span>
will coming.
anyone can help me here?
I am using this code for LIKE and UNLIKE :
AJAX JQUERY:
$('.like_button').die('click').live("click", function () {
var KEY = parseInt($(this).attr("data"));
var ID = $(this).attr("id");
if (KEY == '1') {
var sid = ID.split("likes");
} else {
var sid = ID.split("like");
}
var New_ID = sid[1];
var REL = $(this).attr("rel");
var URL = $.base_url + 'post_like_ajax.php';
var dataString = 'post_id=' + New_ID + '&rel=' + REL;
$.ajax({
type: "POST",
url: URL,
data: dataString,
cache: false,
success: function (html) {
if (html) {
if (REL == 'Like') {
$("#elikes" + New_ID).show('fast').prepend("<span id='you" + New_ID + "'><a href='#'>You</a> like this.</span>");
$("#likes" + New_ID).prepend("<span id='you" + New_ID + "'><a href='#'>You</a>, </span>");
$('#' + ID).html('Unlike').attr('rel', 'Unlike').attr('title', 'Unlike');
} else {
$("#elikes" + New_ID).hide('slow');
$("#you" + New_ID).remove();
$('#' + ID).attr('rel', 'Like').attr('title', 'Like').html('Like');
}
}
}
});
return false;
});
PHP CODE:
<?php
if($login)
{
?>
<a href='#' class='like like_button icontext' id='like<?php echo $post_id;?>' title='<?php echo $like_status;?>' rel='<?php echo $like_status;?>' data=''><?php echo $like_status;?></a>
<a href='#' class='commentopen commentopen_button icontext' id='<?php echo $post_id;?>' rel='<?php echo $post_id;?>' title='Comment'>Yorum yap </a>
<?php if($uid != $post_id) { ?>
<?php } } else { ?>
<a href='<?php echo $index_url; ?>' class='like icontext' >Like</a>
<a href='<?php echo $index_url; ?>' class='commentopen icontext' title='Comment'>Comment</a>
<a href='<?php echo $index_url; ?>' class='share icontext' title='Share'>Share</a>
<?php
}
?>
<?php if($post_like_count>0)
{
$likesuserdata=$POLL->post_Like_Users($post_id);
if($likesuserdata)
{
echo '<div class="likes" id="likes'.$post_id.'">';
$i=1;
$j=count($likesuserdata);
foreach($likesuserdata as $likesdata)
{
$you="likeuser".$post_id;
$likeusername=$likesdata['username'];
if($likeusername == $session_username)
{
$likeusername='You';
$you="you".$post_id;
}
echo '<a href="#" id="'.$you.'">'.$Wall->UserFullName($likeusername).'</a>';
if($j!=$i)
{
echo ', ';
}
$i=$i+1;
}
if($post_like_count>3)
{
$post_like_count=$post_like_count-3;
echo ' and <span id="like_count'.$post_id.'" class="numcount">'.$post_like_count.'</span> others like this.';
}
else
{
echo ' like this.';
}
echo '</div>';
}
}
else
{
echo '<div class="likes" id="elikes'.$post_id.'" style="display:none"></div>';
}
?>
post_like_ajax.php
<?php
include_once 'includes.php';
if(isSet($_POST['post_id']) && isSet($_POST['rel']))
{
$haber_id=$_POST['post_id'];
$rel=$_POST['rel'];
if($rel=='Like')
{
$cdata=$POLL->POST_Like($post_id,$uid);
}
else
{
$cdata=$POLL->POST_Unlike($post_id,$uid);
}
echo $cdata;
}
?>
Upvotes: 0
Views: 1285
Reputation: 934
I think you forgot just to display the div in which you are prepending because for start you added display:none, echo '<div class="likes" id="elikes'.$post_id.'" style="display:none"></div>';
try to change this line:
$("#likes" + New_ID).prepend("<span id='you" + New_ID + "'><a href='#'>You</a>, </span>");
to this:
$("#likes" + New_ID).show().prepend("<span id='you" + New_ID + "'><a href='#'>You</a>, </span>");
Upvotes: 1