我有一個關於我的帖子喜歡和不同的問題。問題是當我點擊.like_button <span id='you"+New_ID+"'><a href='#'>You</a> like this.</span>
沒有顯示。Php喜歡和不像使用JQUERY AJAX
我仍然檢查瀏覽器開發者控制檯。但是當我點擊像按鈕像按鈕將改變,但<span id='you"+New_ID+"'><a href='#'>You</a>, </span>
沒有顯示。但如果我刷新頁面<span id='you"+New_ID+"'><a href='#'>You</a>, </span>
即將到來。
任何人都可以幫助我嗎?
我使用這個代碼像不像:
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代碼:
<?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;
}
?>
從您的瀏覽器打開開發者工具並檢查網絡和控制檯選項卡。你會以更快的速度找到答案。祝你好運。 – 2014-11-02 23:12:09
@FinciucSergiu我仍然與broser開發者控制檯檢查。但是當我點擊Like按鈕Like按鈕會改變,但''span id ='你'+ New_ID +''>You,'不顯示。但是,如果我刷新頁面,那麼即將出現'You,'。 – innovation 2014-11-02 23:17:04