weixin_33701564 2019-12-03 08:34 采纳率: 0%
浏览 103

通过ajax将数据追加到表

I'm having issue with appending my data to table body.

Code

$.ajax({
  type:'GET',
  url:'{{url('dashboard/customer-groups')}}/'+ordID,
  success:function(data){
    console.log(data);  //screenshot below
  }
});

screenshot

data returned by ajax code above in 2 categories (group and customers)

one

HTML

<table id="data-table" class="table table-striped table-bordered">
    <thead>
    <tr>
        <th>#</th>
        <th>Name</th> // from customers array
        <th>Company</th> // from customers array
        <th>Province</th> // from customers array
        <th>City</th> // from customers array
        <th>Email</th> // from customers array
        <th>Industry</th> // from customers array
        <th>Group</th> // from group
    </tr>
    </thead>
    <tbody id="table_customer"></tbody>
</table>

Any idea?

  • 写回答

2条回答 默认 最新

  • csdn产品小助手 2019-12-03 08:42
    关注
        $.ajax({
          type:'GET',
          url:'{{url('dashboard/customer-groups')}}/'+ordID,
          success:function(data){
            const tr = $('tr');
            for (var key in data) {
               var obj = data[key];
               var id = "<td>"+obj.id+"</td>";
    var group_id = "<td>"+obj.group_id+"</td>";
    
    
         // add more columns for other attributes
               var allTds = id+group_id;
             }
            tr.append(allTds);
           $('#data-table').append(tr);
          }
        });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题