title: Returning JSON from EE module
body: <p>I have created a module in Expression Engine (built with codeigniter framework). </p>
  
  <p>I am using AJAX to submit a form, and want JSON responses returned. </p>
  
  <p>The form is submitting correctly through AJAX and I have tested its adding to a db etc with different code.</p>
  
  <p>As some test code for the JSON response I have set up the following:</p>
  
  <pre><code>public function placeItem() {
  
      $arr = array('a' =&gt; 1, 'b' =&gt; 2, 'c' =&gt; 3, 'd' =&gt; 4, 'e' =&gt; 5);
  
      echo json_encode($arr);
  
  } 
  </code></pre>
  
  <p>with:</p>
  
  <pre><code>var options = { 
      success: update,
      url: 'http://www.domain.com/index.php?ACT=41'
  }; 
  
  function update(json) {
      alert(json);        
  }
  
  $('#wishlist-form').submit(function() { 
      $(this).ajaxSubmit(options); 
      return false; 
  }); 
  </code></pre>
  
  <p>This is rerturned:</p>
  
  <pre><code>"a":1,"b":2,"c":3,"d":4,"e":5}&lt;div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;"&gt;
  
  &lt;h4&gt;A PHP Error was encountered&lt;/h4&gt;
  
  &lt;p&gt;Severity: Warning&lt;/p&gt;
  &lt;p&gt;Message:  Cannot modify header information - headers already sent by (output started at /var/sites/d/domain.com/public_html/system/expressionengine/third_party/wishlist/mod.wishlist.php:77)&lt;/p&gt;
  &lt;p&gt;Filename: core/Common.php&lt;/p&gt;
  &lt;p&gt;Line Number: 408&lt;/p&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>Line 77 is : echo json_encode($arr);</p>
  
  <p>Firstly, I can't figure out why the PHP error is displaying.
  Secondly, the JSON is returned in the alert, but if I try to do json.a for example it shows 'undefined'.</p>