title: Display the AJAX response in Table
body: <p>I am trying to display the records based on date range.</p>
  
  <p><strong>Script</strong></p>
  
  <pre><code>$(function() {
    $(document).on("click", "#btnSubmit", function(e) {
      e.preventDefault();
      var info = $("#search").serialize();
      alert(info);
  
      $.ajax({
        type: 'POST',
        url: 'url',
        data: info,
        success: function(response) {
          alert(response);
          var obj = $.parseJSON(response);
          var trHTML = '';
  
          $.each(response, function(i, o) {
            trHTML += '&lt;tr&gt;&lt;td&gt;' + o.patient_name +
              '&lt;/td&gt;&lt;td&gt;' + o.patient_address +
              '&lt;/td&gt;&lt;/tr&gt;';
          });
  
          $('#records_table').append(trHTML);
        }
      });
  
      e.preventDefault();
    });
  });
  </code></pre>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;table class='table table-striped table-bordered table-hover' id='records_table'&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>public function getsearch(){
  
      $this-&gt;load-&gt;model('History_m');
      $fromdate=$this-&gt;input-&gt;post('dateFrom');
      $todate=$this-&gt;input-&gt;post('dateTo');
  
      $date1=date( 'Y-m-d', strtotime($fromdate));
      $date2=date( 'Y-m-d', strtotime($todate));
  
      $result  = $this-&gt;History_m-&gt;search($date1,$date2);
      echo json_encode($result);     
  }
  </code></pre>
  
  <p><strong>Model</strong></p>
  
  <pre><code>function search($date1,$date2){
      $this-&gt;db-&gt;trans_start();
      $query = $this-&gt;db-&gt;query("SELECT * FROM `referral_confirmation_details` WHERE `created_on` &gt;= '".$date1."' AND `created_on` &lt;= '".$date2."'");
      $this-&gt;db-&gt;trans_complete();
      if($query-&gt;num_rows()&gt;=1)
          return $query-&gt;result();
      }
  </code></pre>
  
  <p><strong>AJAX Response</strong></p>
  
  <p>I am getting the output for <code>alert(response)</code> as:</p>
  
  <pre><code>[
     {
        "ID":"1",
        patient_name":"xyz",
        "patient_email":"xyz@gmail.com",
        "gender":"Male",
        "age":"23",
        "address":"xyz",
        "city":"bangalore",
        "password":"fzf1"
     }
  </code></pre>
  
  <p>I am getting the <strong>error</strong> like "Unexpected token A in JSON at position 0".</p>