开发者社区> 问答> 正文

jquery ajax 读取json数据存入表格中

test.txt的json数据如下
[
{"XH":1,"YWName":"业务1","SName":"系统1","QDName":"渠道1","HJNumber":5},
{"XH":2,"YWName":"业务2","SName":"系统2","QDName":"渠道2","HJNumber":6},
{"XH":3,"YWName":"业务3","SName":"系统3","QDName":"渠道3","HJNumber":7}
]

jquery ajax读取json数据的方式

$.getJSON('test.txt',function(data){

}

表格:
screenshot

展开
收起
杨冬芳 2016-07-07 14:45:32 2634 0
1 条回答
写回答
取消 提交回答
  • IT从业
     <script>
    $(document).ready(function(){
       var data = [
    {"XH":1,"YWName":"业务1","SName":"系统1","QDName":"渠道1","HJNumber":5},
    {"XH":2,"YWName":"业务2","SName":"系统2","QDName":"渠道2","HJNumber":6},
    {"XH":3,"YWName":"业务3","SName":"系统3","QDName":"渠道3","HJNumber":7}
    ];
      var $table=$('<table border="1"></table>');
      var $head =$('<tr><td>序号</td><td>业务名称</td><td>系统名称</td><td>渠道名称</td><td>环节数</td><td>操作</td></tr>');
    $table.append($head);
      for(var i=0;i<data.length;i++){
        var row = data[i];
        var $tr = $('<tr></tr>');
        var XH= $('<td>'+row['XH'] + '</td>');
        var YWName= $('<td>'+row['YWName'] + '</td>');
        var SName= $('<td>'+row['SName'] + '</td>');
        var QDName= $('<td>'+row['QDName'] + '</td>');
        var HJNumber= $('<td>'+row['HJNumber'] + '</td>');
        $tr.append(XH).append(YWName).append(SName).append(QDName).append(HJNumber).append('<td></td>');
       $table.append($tr);
      }
      $('body').append($table);
    });
    </script>
    2019-07-17 19:52:49
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载