title: CodeIgniter JSON Response Issue
body: <p>I am having an issue with a Control Panel that I've been working on.  I have a general account settings page.  On this page, the user can perform various functions such as create a new user, change their password, or update their e-mail preferences.</p>
  
  <p>The account creation panel works without any issues.  The data gets POST, and returns a JSON response.</p>
  
  <p>Where I'm having difficult is on the next panel for changing the user's password.  <strong>The data gets POST, and Firebug gets the appropriate response.</strong>  The Chrome Developer JS console gets nothing back, but the data still gets posted.  None of the messages appear where they're supposed to in HTML.  So the function is working properly, if you change your password and refresh the page you get the message from the JSON response.  No server or php errors are reported.</p>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  
  class Ajax extends MY_Controller {
  
  public function __construct() {
          parent::__construct();
  }
  
  public function index()
  {
      if ($this-&gt;input-&gt;is_ajax_request()) {
                  $formData = array();
                  parse_str($this-&gt;input-&gt;post('formData'), $formData);
                  $action = $formData['action'];
                  switch($action){
                      case("createAccount"):
                          $this-&gt;createAccount($this-&gt;input-&gt;post('formData'));
                          break;
                      case("changePassword");
                          echo "Changing password...";
                          $this-&gt;changePassword($this-&gt;input-&gt;post('formData'));
                          break;
                      case("updateEmail");
                          echo "Updating Email settings...";
                          $this-&gt;updateEmail($this-&gt;input-&gt;post('formData'));
                  }
               }
               else {
                   redirect('/', 'refresh');
               }
  }
  
      public function createAccount($data)
      {
          parse_str($data, $_POST); 
          $this-&gt;form_validation-&gt;set_rules('first_name', 'First Name', 'required|xss_clean');
          $this-&gt;form_validation-&gt;set_rules('last_name', 'Last Name', 'required|xss_clean');
          $this-&gt;form_validation-&gt;set_rules('company', 'Company', 'required|xss_clean');
          $this-&gt;form_validation-&gt;set_rules('password', 'Password', 'required|xss_clean');
          $this-&gt;form_validation-&gt;set_rules('password_confirm', 'Password Confirmation', 'required|xss_clean');
          $this-&gt;form_validation-&gt;set_rules('email', 'Email', 'required|valid_email');
         if ($this-&gt;form_validation-&gt;run() == FALSE)
          {
                 $errors = validation_errors();
                 $response = array("response" =&gt; "400",
                                   "message" =&gt; $errors);
          }
          else
          {
          $additional_data = array("first_name" =&gt; $_POST['first_name'], "last_name" =&gt; $_POST["last_name"], "company" =&gt; $_POST['company'], "phone" =&gt; $_POST["phone"]);
          $group_ids = array("2" =&gt; "2");
  
              $account = $this-&gt;ion_auth-&gt;register($_POST['email'], $_POST['password_confirm'], $_POST['email'], $additional_data, $group_ids);
              if($account){
                  $response = array("response" =&gt; "200",
                                    "message" =&gt; "Account Created Successfully", 
                                    "user" =&gt; $_POST['email']);
              }
              else {
                  $response = array("response" =&gt; "400",
                                    "message" =&gt; "This account already exists", 
                                    "user" =&gt; $_POST['email']);
              }
          }
          $this-&gt;json_output($response);
      }
  
       public function changePassword($data)
      {
       parse_str($data, $_POST);
         $this-&gt;form_validation-&gt;set_rules('old', 'Old Password', 'required|xss_clean');
         $this-&gt;form_validation-&gt;set_rules('new', 'New Password', 'required|xss_clean');
         $this-&gt;form_validation-&gt;set_rules('new_confirm', 'Confirm New Password', 'required|xss_clean');
          if ($this-&gt;form_validation-&gt;run() == FALSE)
          {
                 $errors = validation_errors();
                 $response = array("response" =&gt; "400",
                                   "message" =&gt; $errors);
          }
          else
          {
                      $identity = $this-&gt;session-&gt;userdata('identity');
          $change = $this-&gt;ion_auth-&gt;change_password($identity, $this-&gt;input-&gt;post('old'), $this-&gt;input-&gt;post('new'));
          if ($change)
          {
                              $errors = validation_errors();
                              $response = array("response" =&gt; "200",
                                                "message" =&gt; "Password Successfully Changed");
          }
          else
          {
                              $errors = validation_errors();
                              $response = array("response" =&gt; "400",
                                                "message" =&gt; $this-&gt;session-&gt;set_flashdata('message', $this-&gt;ion_auth-&gt;errors()));
  
          } 
          }
          $this-&gt;json_output($response);
      }
   public function json_output($data)
      {
          $this-&gt;output
                          -&gt;set_content_type('application/json')
                          -&gt;set_output(json_encode($data))-&gt;_display();
          exit;
      }
  }
  </code></pre>
  
  <p><strong>jQuery</strong></p>
  
  <pre><code>$("#createAccount").click(function(){
      var formData =  $("#createAccountForm").serialize();
      $.post(base_url + "ajax/index", {
          dataType: "json",
          formData : formData,
          cahce: false
      }, function(data) {
          if(data["response"] == "200")
          {
              $("#modalTitle").html("&lt;i class=\"fa fa-user\"&gt;&lt;/i&gt;&lt;sup&gt;&lt;i class=\"fa fa-plus\"&gt;&lt;/i&gt;&lt;/sup&gt; Client Account Created");
              $("#modalBody").html("&lt;p&gt;The user account for &lt;strong&gt;" + data["user"] + "&lt;/strong&gt; has been created.");
              $("#modalFooter").html("&lt;a href='#' data-dismiss='modal' class='btn btn-info'&gt;OK&lt;/a&gt;");
              $("#createAccountMsg").html("");
              $('#notificationModal').modal('show');
          }
          if(data["response"] == "400")
          {
              $("#createAccountMsg").html("&lt;div class='panel panel-danger'&gt;&lt;div class='panel panel-heading'&gt;&lt;h3&gt;&lt;i class='fa fa-exclamation'&gt;&lt;/i&gt; Error Creating User&lt;/h3&gt;&lt;/div&gt;&lt;div class='panel-body'&gt;"+data["message"]+"&lt;/div&gt;&lt;/div&gt;")
          }
      });
      return false;
  });
  
  $("#changePassword").click(function(){
     var formData = $("#changePasswordForm").serialize();
     $.post(base_url + "ajax/index", {
         dataType: "json",
         formData: formData,
         cahce: false
     }, function(data) {
        if(data["response"] == "200")
          {
              $("#modalTitle").html("&lt;i class=\"fa fa-gear\"&gt;&lt;/i&gt;&lt;/sup&gt; Password Changed");
              $("#modalBody").html("&lt;p&gt;Your password has been successfully changed.");
              $("#modalFooter").html("&lt;a href='#' data-dismiss='modal' class='btn btn-info'&gt;OK&lt;/a&gt;");
              $("#createAccountMsg").html("");
              $('#notificationModal').modal('show');
          }
          if(data["response"] == "400")
          {
              $("#changePasswordMsg").html("&lt;div class='panel panel-danger'&gt;&lt;div class='panel panel-heading'&gt;&lt;h3&gt;&lt;i class='fa fa-exclamation'&gt;&lt;/i&gt; Error Changing Password&lt;/h3&gt;&lt;/div&gt;&lt;div class='panel-body'&gt;"+data["message"]+"&lt;/div&gt;&lt;/div&gt;")
          }
     });
      return false;
  }); 
  }); 
  </code></pre>