title: Really simple ajax + codeigniter
body: <p>I'm trying to learn the fundamentals of ajax but I can't really make it work. Here's what I'm trying.</p>
  
  <p>File:create_comment.php (view)</p>
  
  <pre><code> &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  
  &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js"&gt;&lt;/script&gt;
  
  &lt;script&gt;
     $(function(){
         $("#comment").submit(function(){
  
           var name = $("#name").val();
  
  
           $.ajax({
             type: "POST",
             url: "&lt;?php echo base_url(); ?&gt;index.php/comment/create",
             data: "name="+name,
             dataType: 'json',
  
             success: function(result){    
                  $('#write').html(result.returnValue);
             },
             error: function(xhr, status, error) { 
                  alert('Error: '+ xhr.status+ ' - '+ error); },
  
           });
  
           return false;  
  
        });
     });
  &lt;/script&gt;
  
  &lt;title&gt;Untitled Document&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;h3&gt;New Comment&lt;/h3&gt;
  &lt;form id="comment" method="post"&gt;
  &lt;label&gt;Name: &lt;/label&gt;&lt;input type="text" id="name" name="name" /&gt;&lt;br
  &lt;label&gt;&amp;nbsp;&lt;/label&gt;&lt;input type="submit" value="Submit" /&gt;
  &lt;/form&gt;
  
  &lt;div id="write" &gt;&lt;/div&gt;
  &lt;!-- here is the script that will do the ajax. It is triggered when the form is submitted --&gt;&lt;/body&gt;&lt;/html&gt;
  </code></pre>
  
  <p>File: comment.php (controller)</p>
  
  <pre><code>&lt;?php
  
  class Comment extends CI_Controller{
  
  function  __construct() {
  
      parent::__construct();
      $this-&gt;load-&gt;helper('url');
  }
  
  function index(){
  
      $this-&gt;load-&gt;view('create_comment');
  
  
  }
  
  function create(){
  
      if($_POST) {
             echo json_encode(array("returnValue"=&gt;"This is returned from PHP")); 
      }
  }
  
  
  }
  ?&gt;
  </code></pre>
  
  <p>What I'm always getting when I submit the for is: Error: 0 - OK
  This means that I'm not even getting the 'success' function. If instead of echoing, I use 'return', then I'm going into the success function (but obviously I cannot output the results).</p>
  
  <p>I know this must be the easiest question ever but what am I doing wrong?</p>