Shall I use json_encode() when returning Array data to be accessed by JQuery AJAX?
<p>I was trying to use JQuery AJAX to grab some data retrieved from the database in cakePHP 1.26:<br/></p>

<pre><code> function testing(){
    $user = $this-&gt;user-&gt;findallbyuser_id("1");
    return $user;
}
</code></pre>

<p>and here is the output from cakePHP built-in function Debug($user):</p>

<pre><code>Array
(
    [user_id] =&gt; 1
    [name] =&gt; hello  
)
</code></pre>

<p>Here is the JQuery part:</p>

<pre><code>  $.ajax({
      type: "POST",
      url: curl,   
      success: function(data){ 
      alert(data); }
});
</code></pre>

<p>Here is the Alert message:</p>

<pre><code>Array &lt;!--0.082--&gt;
</code></pre>

<p>Later, I found that the Alert message showed me something different after I altered
the code:</p>

<pre><code> function testing(){
    $user = $this-&gt;user-&gt;findallbyuser_id("1");
    return json_encode($user);
}
</code></pre>

<p>And here is the new output from the Alert message box:<br/></p>

<pre><code>{"user_id":"1","name":"hello"}&lt;!--0.0953--&gt;
</code></pre>

<p>But I don't know how to print out the data returned from JQuery AJAX in this way:</p>

<pre><code>User ID: 1
User name: hello
</code></pre>
