title: Codeigniter - Delete without refreshing page
body: <p>I have a problem with ajax delete in codeigniter. I want to delete without refreshing page</p>
  
  <p>Here is my controller   </p>
  
  <pre><code>    function delete($id_post='')
      {
      $hapus=$this-&gt;home_model-&gt;delete($id_post);
                  if($hapus){
                  echo "true";
                  } else {
                  echo "error";
        }
      }
  </code></pre>
  
  <p>here is my model:</p>
  
  <pre><code>function delete($id_post='')
      { 
      $sql  = "DELETE FROM post WHERE id_post=?";
      return $this-&gt;db-&gt;query($sql,array($id_post));
  }
  </code></pre>
  
  <p>Here is my view and javascript:</p>
  
  <pre><code>&lt;?php foreach($news as $data):?&gt;
   &lt;div id="row"&gt;
  &lt;?php echo $data['news']?&gt;
  Post by: &lt;?php echo ['username']?&gt;
  &lt;button onClick="return confirm('Sure to delete?')" class="btn-danger btn-xs delete" id="&lt;?php echo $data['id_post']?&gt;"&gt;delete&lt;/button&gt;
  &lt;/div&gt;
  &lt;?endforeach;?&gt;
  
      &lt;script languge="javascript" type="text/javascript"&gt;
     $(document).ready(function(){ // added
      $(".delete").click(function(){
          //var id_post = this.id;
          var btn = this;
          e.preventDefault();
              $.ajax({
                 type: "POST",
                 url: "&lt;?php echo base_url()?&gt;delete",
                 cache: false,
                 data: "id_post="+$(this),
                 success: function(reaksi){
                     if (reaksi=="true"){
                         alert('Success delete');
                     } else {
                         alert('failed');
                     }
                  }
              });
      return false
      });
     }); // added
  &lt;/script&gt;
  </code></pre>
  
  <p>When i click delete, ajax not even trigerred. Any answer?</p>