开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜