title: How to return JSON from a CakePHP 2.2 controller?
body: <p>I'm invoking a controller function:</p>
  
  <pre><code>$.get("http://localhost/universityapp/courses/listnames", function(data){
      alert("Data Loaded: " + data);
  });
  </code></pre>
  
  <p>And in my Controller:</p>
  
  <pre><code>public function listnames() {
      $data = Array(
          "name" =&gt; "Sergio",
          "age" =&gt; 23
      );
      $this-&gt;set('test', $data);
      $this-&gt;render('/Elements/ajaxreturn'); // This View is declared at /Elements/ajaxreturn.ctp
  }
  </code></pre>
  
  <p>And in that View:</p>
  
  <pre><code>&lt;?php echo json_encode($asdf); ?&gt;
  </code></pre>
  
  <p>However, the Action is returning the entire page including the Layout content (header, footer, navigation).</p>
  
  <p>What am I missing here? How can I return just the JSON data without the Layout content?</p>