title: Codeigniter - Create Vote Up system in codeigniter
body: <p>I am trying to create vote up in my codeigniter named "like". I use this method, that i just found in <a href="http://www.technicalkeeda.com/codeigniter-tutorials/voting-system-using-jquery-ajax-and-php-codeigniter-framework" rel="nofollow noreferrer">http://www.technicalkeeda.com/codeigniter-tutorials/voting-system-using-jquery-ajax-and-php-codeigniter-framework</a></p>
  
  <p>And update is run successfully on database, But the problem is the result of like in view is not showing and the output is text from localhost "Sorry unable to update". And when i refresh the page, the result of "like" showing up.</p>
  
  <p>This is the <strong>Controller</strong>:</p>
  
  <pre><code>function voteme(){      
      $id_vote=  $this-&gt;input-&gt;post('id_vote');
      $upOrDown=  $this-&gt;input-&gt;post('upOrDown');
      $status ="false";
      $updateRecords = 0;     
      if($upOrDown=='upvote'){
          $updateRecords = $this-&gt;home_model-&gt;updateUpVote($id_vote);
      }
      if($updateRecords&gt;0){
          $status = "true";
      }
      echo $status;
      $data['id_vote'] = $id_vote;
      redirect ('home',$data);
  }
  </code></pre>
  
  <p>This is <strong>Model</strong>:</p>
  
  <pre><code>function updateUpVote($id_vote){
      $sql = "UPDATE vote set like = like+1 WHERE id_vote =?";
      $this-&gt;db-&gt;query($sql, array($id_vote));
      return $this-&gt;db-&gt;affected_rows();
  }
  </code></pre>
  
  <p>Here is the <strong>view</strong>:</p>
  
  <pre><code>&lt;button class="btn btn-success voteme" id="3_upvote"&gt;&lt;span id="&lt;?php echo $data['id_vote']?&gt;_upvote_result" &gt;&lt;?php echo $data['like']?&gt;&lt;/span&gt; &lt;b&gt;Like&lt;/b&gt;&lt;/button&gt;
  </code></pre>
  
  <p>This is <strong>javascript</strong>:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  $(document).ready(function(){
        $(".voteme").click(function() {
          var id_vote = this.id;
          var upOrDown = id_vote.split('_'); 
          $.ajax({
              type: "post",
              url: "http://localhost/ngelol/home/voteme",
              cache: false,               
              data:'id_vote='+upOrDown[0] + '&amp;upOrDown=' +upOrDown[1],
              success: function(response){                
                  try{
                      if(response=='true'){   
                          var newValue = parseInt($("#"+id_vote+'_result').text()) + 1;            
                          $("#"+id_vote+'_result').html(newValue);
                      }else{
                          alert('Sorry Unable to update..');
                      }
                  }catch(e) {     
                      alert('Exception while request..');
                  }       
              },
              error: function(){                      
                  alert('Error while request..');
              }
           });
      });
  });
  </code></pre>
  
  <p></p>
  
  <p>How to get this result of like without refreshing page?</p>
  
  <p>Many Thanks....</p>
  
  <p><strong>Update</strong>:</p>
  
  <p>I have new problem guys, does anyone know how to redirect page in javascript.. I mean, to use vote we need to login first, then i replace
   <code>alert('Sorry Unable to update..');</code> 
  with
   <code>url: "localhost/latihan/login";</code> but it didn't work... thanks for help before</p>