真的很简单的ajax + codeigniter

I'm trying to learn the fundamentals of ajax but I can't really make it work. Here's what I'm trying.

File:create_comment.php (view)

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js"></script>

<script>
   $(function(){
       $("#comment").submit(function(){

         var name = $("#name").val();


         $.ajax({
           type: "POST",
           url: "<?php echo base_url(); ?>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;  

      });
   });
</script>

<title>Untitled Document</title>
</head>

<body>
<h3>New Comment</h3>
<form id="comment" method="post">
<label>Name: </label><input type="text" id="name" name="name" /><br
<label>&nbsp;</label><input type="submit" value="Submit" />
</form>

<div id="write" ></div>
<!-- here is the script that will do the ajax. It is triggered when the form is submitted --></body></html>

File: comment.php (controller)

<?php

class Comment extends CI_Controller{

function  __construct() {

    parent::__construct();
    $this->load->helper('url');
}

function index(){

    $this->load->view('create_comment');


}

function create(){

    if($_POST) {
           echo json_encode(array("returnValue"=>"This is returned from PHP")); 
    }
}


}
?>

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).

I know this must be the easiest question ever but what am I doing wrong?

Guys I found the solution.

I had set $config['compress_output'] = TRUE;

If I set it to FALSE everything works fine!!

Thank you all for your time!!

enter image description here

To fix compression issue you have to enable it in php.ini without disable compress from codeigniter.