How to print Array data retrieved from Database using JQuery
I am using cakePHP 1.26, and JQuery.
In a TestingController, I got this line of code
function testing(){
$r = $this->User->findallByuser_id(1);
}
and I am using JQuery Ajax to retrieve the data from function testing():
 $.ajax({
      type: "POST",
      url: curl,   
      success: function(data){ 
      alert(data);  
      }     
Here is the JQuery Alert output:
Array
And this is cakePHP output:
Array
(
    [User] => Array
        (
            [user_id] => 50
            [name] => hello
        )
   开发者_如何学编程    ...
)
Well, iterate it like an ordinary array:
for (var i = 0, l = data.length; i < l; i++)
{
   alert(data[i]["user"]["id"]);
}
I suppose you will also need some template engine for JavaScript to perform easy HTML generation. Check mustache.js.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论