title: Delete function using AJAX in CodeIgniter
body: <p><strong>PROBLEM SOLVED</strong>.. I update my code accordingly.. Thanks all</p>
  
  <p>Intro: My code display array of message traces (each message display in grey-panel). User can delete unwanted message by click on delete button, the message will be deleted in both DB and disappear from screen.</p>
  
  <p>Seems my delete function is not working.. Appreciate for advice.. I don't know AJAX.. this is my first try. Thanks in advance.</p>
  
  <p>The following are my code:</p>
  
  <p>ajax code: </p>
  
  <pre><code>$(document).ready(function(){
      $("body").on("click", "#responds .del_button", function(e) {
          e.preventDefault();
           var $btn = $(this),
               $li = $btn.closest('li');
  
          var traceId = $li.data('trace-id');
  
          jQuery.ajax({
                    type: 'post', 
                    url: 'traceDelete', 
                    dataType: 'text',
  
                    data: { 'traceId': traceId },
  
                    success: function (res) {
                        if (res === '1') {
                            $btn.fadeOut();
                        }
                    },
                    error: function (xhr, ajaxOptions, thrownError){
                        alert(thrownError);
                    }
          });
      });
  </code></pre>
  
  <p>part of view code:</p>
  
  <pre><code>&lt;ul id="responds"&gt;
      &lt;?php foreach ($line as $dataName =&gt; $contents){ ?&gt;    
          &lt;li data-trace-id="&lt;?php echo $contents-&gt;trace_id; ?&gt;"&gt;
              &lt;div class="grey-panel" style="text-align:right"&gt;
                  &lt;div class="del_wrapper" id="&lt;?php echo $contents-&gt;trace_id; ?&gt;"&gt;
                      &lt;a href="#" class="del_button" id="&lt;?php echo $contents-&gt;trace_id; ?&gt;" data-hover="tooltip" title="Delete this message &lt;?php echo $contents-&gt;trace_id; ?&gt;"  &gt;
                          &lt;i class="fa fa-times"&gt;&lt;/i&gt;
                       &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="col-sm-12 col-xs-12"&gt;
                    &lt;?php print $contents-&gt;trace_hdr.'&lt;br /&gt;';
                    print $contents-&gt;trace_src.'&lt;br /&gt;';
                    print $contents-&gt;trace_dest.'&lt;br /&gt;';
                    // some other things ?&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/li&gt; 
      &lt;?php } ?&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>controller code:</p>
  
  <pre><code>public function traceDelete($traceID) {
      if ($traceId = $this-&gt;input-&gt;post('traceId')) {
      return $this-&gt;model_general-&gt;deleteTrace($traceId);
      }
      return false;
  }
  </code></pre>
  
  <p>model code:</p>
  
  <pre><code>public function deleteTrace($id) {
      $this-&gt;db-&gt;where('trace_id', $id);
      $this-&gt;db-&gt;delete('trace_tbl');
      return $this-&gt;db-&gt;affected_rows() &gt; 1 ? true:false;
  }
  </code></pre>