title: Without refresh the page how to display the values from database using ajax/jQuery
body: <p>After inserting data into the database through jQuery/ajax, while fetching values from database without refresh the page how to display the database values using codeigniter? </p>
  
  <p><a href="https://i.stack.imgur.com/jCrn8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jCrn8.png" alt="display form"></a></p>
  
  <p>This is my code:</p>
  
  <p>Script:</p>
  
  <pre><code> &lt;script&gt;
          $(document).ready(function(){
              $("#personal-info").submit(function(e){
                 e.preventDefault();
                 var suppid = $("#suppid").val();
                 var proid = $("#proid").val();
                 var custid = $("#custid").val();
                  var message = $("#message").val();
  
                  $.ajax({
                      type: "POST",
                      url: "&lt;?php echo base_url(); ?&gt;index.php/Profile_cntrl/buyer_communication",
                      data: {suppid:suppid,proid:proid,custid:custid,message:message},
                      success:function(data)
                      {
                          alert('SUCCESS!!');
                      },
                      error:function()
                      {
                          alert('fail');
                      }
                  });
              });
          });
      &lt;/script&gt;
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>public function buyer_communication() {
  
          $result1 = $this-&gt;Profile_model-&gt;fetch_Data($product_id);
  
  
          $Userid = $this-&gt;session-&gt;userdata('id');
          $result3 = $this-&gt;session-&gt;userdata('tt');
          $data4 = array(
              'message' =&gt; $this-&gt;input-&gt;post('message'),
              'supplier_id' =&gt; $this-&gt;input-&gt;post('suppid'),
              'product_id' =&gt; $this-&gt;input-&gt;post('proid'),
              'Customer_id' =&gt; $this-&gt;input-&gt;post('custid'),
              'From' =&gt; $result3,
          );
  
          $this-&gt;Profile_model-&gt;buyer_insert($data4);
  
          redirect('welcome/buyermessageview?id=' . $product_id);
      }
  </code></pre>
  
  <p>Model:</p>
  
  <pre><code>function buyer_insert($data4) {
          $this-&gt;db-&gt;insert('communication', $data4);
          return ($this-&gt;db-&gt;affected_rows() != 1) ? false : true;
      }
  </code></pre>
  
  <p>Form:</p>
  
  <pre><code>&lt;form class="form-horizontal" method="POST" id="personal-info"  role="form" action="#"&gt; 
                              &lt;div class="panel-footer"&gt;
                                  &lt;div class="input-group"&gt;
  
                                      &lt;input type ="hidden" name="suppid" id="suppid" value="&lt;?php echo $row-&gt;supplier_id; ?&gt;" class="form-control" /&gt;
                                      &lt;input type ="hidden" name="proid" id="proid" value="&lt;?php echo $row-&gt;product_id; ?&gt;" class="form-control" /&gt;
                                      &lt;input type ="hidden" name="custid" id="custid" value="&lt;?php echo $row-&gt;Customer_id; ?&gt;" class="form-control" /&gt;
  
  
  
                                      &lt;input id="message" name="message" type="text" class="form-control input-sm chat_input" placeholder="Write your message here..." /&gt;
                                      &lt;span class="input-group-btn"&gt;
                                          &lt;button class="btn btn-primary btn-sm" id="submit-p" name="submit-p"&gt;Send&lt;/button&gt;
                                          &lt;!--&lt;input type="submit" name="submit-p" id="submit-p" value="send" class="btn btn-primary btn-sm" &gt;--&gt;
                                      &lt;/span&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/form&gt;
  </code></pre>