title: Display AJAX success response in Table
body: <p>How to display the value in table..I am not able to display the value.In ajax i've sent all the value and after retrieving the records from database. I've to display the result in table</p>
  
  <p>Output is </p>
  
  <pre><code> [{"ID":"15","patient_name":"Sangeeta","patient_email":"sangeetha@gmail.com","gender":"Female","age":"26","address":"Jayanagar","city":"Bangalore","laboratory_name":"Anand","laboratory_address":"bsk","laboratory_place":"bengaluru","referral_pat_id":"18","active":"1","created_on":"2017-06-13"}]
  </code></pre>
  
  <p>How to retrieve each value</p>
  
  <p>AJAX Script</p>
  
  <pre><code>$(document).ready(function(){
  $('#myModal').on('show.bs.modal', function (e) {
      var rowid = $(e.relatedTarget).data('id');
      alert(rowid);
      console.log(rowid);
      $.ajax({
          type : 'post',
          url : 'url', //Here you will fetch records 
          data :  'id='+ rowid, //Pass $id
          success : function(resp){
            alert(resp);
           var trHTML = '';
                      $.each(resp, function (i, userData) {
                          for (i = 0; i &lt; resp.UserData.length; i++) {
          alert(trHTML);
  
                              trHTML +=
                                  '&lt;tr&gt;&lt;td&gt;'
                                  + resp.userData[i].ID
                                  + '&lt;/td&gt;&lt;td&gt;'
                                  + resp.userData[i].patient_name
                                  + '&lt;/td&gt;&lt;td&gt;'
                                  + resp.userData[i].patient_email 
                                  + '&lt;/td&gt;&lt;/tr&gt;';
                          }
                      });
                      $('#tBody').append(trHTML);
          }
      });
    });
   });
  </code></pre>
  
  <p>Controller</p>
  
  <pre><code> public function fetch_records()
   {
      print_r($_POST);
      $this-&gt;load-&gt;model('Physician_confirm_m');
  
      $id = $_POST['id']; //escape string
      print_r($id);
      $result=$this-&gt;Physician_confirm_m-&gt;fetch_history_records($id);
      echo json_encode($result);      
  }
  </code></pre>
  
  <p>Model</p>
  
  <pre><code> public function fetch_history_records($id)
   {
   $this-&gt;db-&gt;where('referral_pat_id',$id);
   $this-&gt;db-&gt;from('referral_confirmation_details');
   $q = $this-&gt;db-&gt;get();
   return $q-&gt;result();
   }
  </code></pre>
  
  <p>HTML</p>
  
  <pre><code> &lt;button type="button" class="btn btn-info disablebtn" style="text-align: center;" data-toggle="modal" data-target="#myModal" data-id="&lt;?php echo $post-&gt;referral_patient_id;?&gt;"&gt;&lt;i class="fa fa-history" aria-hidden="true"&gt;&lt;/i&gt;&lt;strong&gt; HISTORY&lt;/strong&gt;&lt;/button&gt;
  
  &lt;div class="modal-body"&gt; 
        &lt;table&gt;
  
          &lt;tbody id="tBody"&gt;&lt;/tbody&gt;
        &lt;/table&gt;
   &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>