title: Updating value on page from database using ajax
body: <p>I am updating the database whenever a user clicks the like button. The update is successfully done but the problem is in updating the new fetched value from the database.</p>
  
  <p>Control Function on which ajax is posting data :</p>
  
  <pre><code>public function plusrepo()
  {
      if($this-&gt;input-&gt;is_ajax_request())
      {
          $this-&gt;load-&gt;model('themodel');
          $rep['updated'] = $this-&gt;themodel-&gt;addrepo($this-&gt;input-&gt;post('resid'));
          echo $rep['updated'][0]." &lt;span&gt;Reputation&lt;/span&gt;";
      }
  }
  </code></pre>
  
  <p>This is how i am selecting from table and returning the result array.</p>
  
  <pre><code>$this-&gt;db-&gt;select('repo');
  $this-&gt;db-&gt;from('restaurants');
  $this-&gt;db-&gt;where('id', $id);
  $result = $this-&gt;db-&gt;get();
  return $result-&gt;result_array();
  </code></pre>
  
  <p>My Ajax function on success does this :</p>
  
  <pre><code>success: function(){
           alert("Success");
           $(this).addClass('.up_arrow').removeClass('.up_arrowed');
           $('.rep_count').html(data);
           }
  </code></pre>
  
  <p>What is wrong? I'm confused.</p>
  
  <p>Edited
  This is the complete function for ajax</p>
  
  <pre><code>$('.up_arrow').each(function() {
      $(this).click(function(event) {
          event.preventDefault();
          var resid = $(this).attr('name');
  
          var post_data = {
              'resid' : resid,
              '&lt;?php echo $this-&gt;security-&gt;get_csrf_token_name(); ?&gt;' : '&lt;?php echo $this-&gt;security-&gt;get_csrf_hash(); ?&gt;'
          };
  
          if(resid){
              $.ajax({
                  type: 'POST',
                  url: "/ci_theyaw/restaurants/plusrepo",
                  data: post_data,
                  success: function(data){
                      console.log(data);
                      // alert(data);
                      // $(this).addClass('.up_arrow').removeClass('.up_arrowed');
                      // $('.rep_count').html(data);
                  },
                  error: function (xhr, ajaxOptions, thrownError) {
                      alert(xhr.status);
                      console.log(xhr.responseText);
                      alert(thrownError);
                  }
              });
          }
      });
  });
  </code></pre>