title: How to Insert and display record without refreshing web page in codeigniter version?
body: <p>I have a code here of inserting and displaying record without refreshing web page using ajax and plain php but I don't know how to set this up using codeigniter. Please help. Here are the codes</p>
  
  <p><strong>inserting.php</strong> </p>
  
  <pre><code>&lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/
   libs/jquery/1.3.0/jquery.min.js"&gt;
  &lt;/script&gt;
  &lt;script type="text/javascript" &gt;
  $(function() {
  $(".comment_button").click(function() {
  
  var test = $("#content").val();
  var dataString = 'content='+ test;
  
  if(test=='')
  {
    alert("Please Enter Some Text");
  }
  else
  {
   $("#flash").show();
   $("#flash").fadeIn(400).html('&lt;img src="ajax-loader.gif" align="absmiddle"&gt;
    &lt;span class="loading"&gt;Loading Comment...&lt;/span&gt;');
  
    $.ajax({
     type: "POST",
     url: "demo_insert.php",
     data: dataString,
     cache: false,
     success: function(html){
     $("#display").after(html);
     document.getElementById('content').value='';
     document.getElementById('content').focus();
     $("#flash").hide();
     }
   });
    } return false;
  });
  });
  &lt;/script&gt;
  // HTML code
  &lt;div&gt;
  &lt;form method="post" name="form" action=""&gt;
  &lt;h3&gt;What are you doing?&lt;/h3&gt;
  &lt;textarea cols="30" rows="2" name="content" id="content" maxlength="145" &gt;
  &lt;/textarea&gt;&lt;br /&gt;
  &lt;input type="submit" value="Update" name="submit" class="comment_button"/&gt;
  &lt;/form&gt;
  &lt;/div&gt;
  &lt;div id="flash"&gt;&lt;/div&gt;
  &lt;div id="display"&gt;&lt;/div&gt;
  </code></pre>
  
  <p><strong>demo_insert.php
  PHP Code display recently inserted record from the database.</strong></p>
  
  <pre><code>&lt;?php
    include('db.php');
    if(isSet($_POST['content']))
    {
     $content=$_POST['content'];
     mysql_query("insert into messages(msg) values ('$content')");
     $sql_in= mysql_query("SELECT msg,msg_id FROM messages order by msg_id  desc");
      $r=mysql_fetch_array($sql_in);
     }
    ?&gt;
   &lt;b&gt;&lt;?php echo $r['msg']; ?&gt;&lt;/b&gt;
  </code></pre>