从ajax响应数据生成表

时间:2015-11-03 13:55:15

标签: php jquery html ajax

我想使用jquery生成这个数据的表格。怎么???

我从数据库查询获得的这一组数据

Array
(
    [0] => stdClass Object
        (   [id] => 61
            [name] => Habib
            [timeview] => 3.56
            [monthnew] => july     
       )
    [1] => stdClass Object
        (   [id] => 61
            [name] => Habib
            [timeview] => 2.75
            [monthnew] => august   
        )
    [2] => stdClass Object
        (   [id] => 61
            [name] => Habib
            [timeview] => 4.81
            [monthnew] => september
        )
)

这是ajax方法.....

    ajax.done(function(data) {
        // What code should be here.....
    }

1 个答案:

答案 0 :(得分:0)

你想要这样的东西:$ table将是你要追加的表。如果您想了解更多详情,请告诉我们

 $table = jQuery('#table');

    $.ajax({
      type: "POST",
      url: "your-script.php",
      success: function (data) {
        for(var i = 0; i < data.length; i ++) {
          $table.append("<tr>" + data[i].text + "</tr>");
        }
      }
    });

(参考:http://api.jquery.com/jquery.ajax/