title: Changing data dynamically using Ajax in CodeIgniter
body: <p>I have this like button, when I click this one, the no of likes will change automatically. The number of likes is displayed above the button. To do this, I've used ajax to implement this function.</p>
  
  <p>This is my code in the View:</p>
  
  <pre><code>&lt;p id='state'&gt;
     &lt;i class='fa fa-thumbs-up'&gt;&lt;/i&gt; &lt;?php echo $countLike;?&gt; likes &amp;bull; 
     &lt;i class='fa fa-thumbs-down'&gt;&lt;/i&gt; &lt;?php echo $countDisLike;?&gt; dislikes&lt;/p&gt;
  
     &lt;button class='detailButton' name='like_name' id='click_like' value='&lt;?php echo $link;?&gt;' title='Like this post'&gt;&lt;i class='fa fa-thumbs-up'&gt;&lt;/i&gt; Like&lt;/button&gt;
  </code></pre>
  
  <p>Javascript code above the view:</p>
  
  <pre><code>&lt;script type="javascript/text"&gt;
  $(document).ready(function){
    $("#click_like").click(function(event){
      event.preventDefault();
      var id = document.getElementById("click_name").value;
      jQuery.ajax({
        type:"GET",
        url: "&lt;?php echo base_url();?&gt;index.php/photoCheese/like_total/",
        dataType:'json',
        data: {like_id = id},
        success: function(res){
          if(res){
            jQuery("div#state").html(res.no_likes);
          }      
        }
      });
    });
  });
  </code></pre>
  
  <p></p>
  
  <p>My controller:</p>
  
  <pre><code>public function like_total(){
          $id = $this-&gt;session-&gt;userdata('userID');
          $upload = $_GET['like_id'];
          $data = array('like' =&gt; 1,
                          'userID'=&gt;$id,
                          'uploadID'=&gt;$_GET['like_id']);
  
          $this-&gt;photoCheese_model-&gt;get_like_total($data,$upload);
  
          return json_encode($data);
      }
  </code></pre>
  
  <p>Model:</p>
  
  <pre><code>public function get_like_total($data,$uplaod){
          $success = $this-&gt;db-&gt;insert('tbl_like',$data);
  
          if($success){
              $this-&gt;db-&gt;select('uploadID,SUM(`like`) as no_likes',false);
              $this-&gt;db-&gt;where('uploadID',$upload);
              $this-&gt;db-&gt;where('like !=',2);
  
              $query = $this-&gt;db-&gt;get();
  
  
          }
          return $query-&gt;result_array();
      }
  </code></pre>
  
  <p>When I try to run this code, it has no effect. I mean, it shows no result at all. I'm new to ajax and it is my first time also to implement this one. Please, help me with this one. Thanks a lot.</p>