title: Php Like and Unlike using JQUERY AJAX
body: <p>I have one question about my post like and unlike. The problem is when i click .like_button the <code>&lt;span id='you"+New_ID+"'&gt;&lt;a href='#'&gt;You&lt;/a&gt; like this.&lt;/span&gt;</code> not showing.</p>
  
  <p>I still check with browser developers console. But when i click Like button Like button will changed but <code>&lt;span id='you"+New_ID+"'&gt;&lt;a href='#'&gt;You&lt;/a&gt;, &lt;/span&gt;</code> not showing. But if i refresh the page <code>&lt;span id='you"+New_ID+"'&gt;&lt;a href='#'&gt;You&lt;/a&gt;, &lt;/span&gt;</code> will coming.</p>
  
  <p>anyone can help me here?</p>
  
  <p>I am using this code for LIKE and UNLIKE :</p>
  
  <p><strong>AJAX JQUERY:</strong></p>
  
  <pre><code>$('.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 + '&amp;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("&lt;span id='you" + New_ID + "'&gt;&lt;a href='#'&gt;You&lt;/a&gt; like this.&lt;/span&gt;");
                      $("#likes" + New_ID).prepend("&lt;span id='you" + New_ID + "'&gt;&lt;a href='#'&gt;You&lt;/a&gt;, &lt;/span&gt;");
                      $('#' + 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;
  });
  </code></pre>
  
  <p><strong>PHP CODE:</strong></p>
  
  <pre><code>&lt;?php 
  if($login)
  {
  ?&gt;
  &lt;a href='#' class='like like_button icontext' id='like&lt;?php echo $post_id;?&gt;' title='&lt;?php echo $like_status;?&gt;' rel='&lt;?php echo $like_status;?&gt;' data=''&gt;&lt;?php echo $like_status;?&gt;&lt;/a&gt; 
  &lt;a href='#' class='commentopen commentopen_button icontext' id='&lt;?php echo $post_id;?&gt;' rel='&lt;?php echo $post_id;?&gt;' title='Comment'&gt;Yorum yap &lt;/a&gt; 
  &lt;?php if($uid != $post_id) { ?&gt;
  
  &lt;?php } } else { ?&gt;
  &lt;a href='&lt;?php echo $index_url; ?&gt;' class='like icontext' &gt;Like&lt;/a&gt; 
  &lt;a href='&lt;?php echo $index_url; ?&gt;' class='commentopen icontext'  title='Comment'&gt;Comment&lt;/a&gt;
  &lt;a href='&lt;?php echo $index_url; ?&gt;' class='share icontext'  title='Share'&gt;Share&lt;/a&gt;     
  &lt;?php   
  }
  ?&gt;
  
  
  &lt;?php if($post_like_count&gt;0) 
  { 
  $likesuserdata=$POLL-&gt;post_Like_Users($post_id);
  if($likesuserdata)
  {
  echo '&lt;div class="likes" id="likes'.$post_id.'"&gt;';
  $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 '&lt;a href="#" id="'.$you.'"&gt;'.$Wall-&gt;UserFullName($likeusername).'&lt;/a&gt;';
  if($j!=$i)
  {
  echo ', ';
  }
  $i=$i+1;
  }
  
  if($post_like_count&gt;3)
  {
  $post_like_count=$post_like_count-3;
  echo ' and &lt;span id="like_count'.$post_id.'" class="numcount"&gt;'.$post_like_count.'&lt;/span&gt; others like this.'; 
  }
  else
  {
  echo ' like this.'; 
  }
  
  echo '&lt;/div&gt;';
  }
  }
  else
  {
  echo '&lt;div class="likes" id="elikes'.$post_id.'" style="display:none"&gt;&lt;/div&gt;';
  }
  ?&gt;
  </code></pre>
  
  <p><strong>post_like_ajax.php</strong></p>
  
  <pre><code>&lt;?php 
  include_once 'includes.php';
  
  if(isSet($_POST['post_id']) &amp;&amp; isSet($_POST['rel']))
  {
  $haber_id=$_POST['post_id'];
  $rel=$_POST['rel'];
  if($rel=='Like')
  {
  $cdata=$POLL-&gt;POST_Like($post_id,$uid); 
  }
  else
  {
  $cdata=$POLL-&gt;POST_Unlike($post_id,$uid);   
  }
  echo $cdata;
  }
  ?&gt;
  </code></pre>