• jq:get获取json数据并以表格形式生成到页面


    <!DOCTYPE html>

    <html>

    <head>

    <meta charset="utf-8">

    <title>jq-get方法</title>

    <script type="text/javascript" src="../jquery-2.1.3.min.js"></script>

    <script type="text/javascript">

    $(function(){

                         $("input").click(function(){

                                 $.get("test.json",function(data){

                                         var data=data;

                                         var str="<table  border=1 width=100%>";

                                         str+="<tr>";

                                         for(var n in data[0]){

                                                 str+="<th>"+n+"</th>";

                                         }

                                         str+="</tr>";

                                         for(var i=0;i<data.length;i++){

                                                 str+="<tr>";

                                                 for(var n in data[i]){

                                                         str+="<td align='center'>"+data[i][n]+"</td>";

                                                 }

                                                 str+="</tr>";

                                         }

                                         str+="</table>";

                                         $("div").html(str);

                                 })

                         })

                 })

    </script> 

    </head> 

    <body>

    <input type="button" value="向服务器发出异步请求" />

    <div></div>

    </body> 

    </html>

    test.json文件:

    [

    {

    "name": "艳艳",

    "pass": "123456",

    "age": "26"

    },

    {

    "name": "张三",

    "pass": "88888888",

    "age": "28"

    },

    {

    "name": "李四",

    "pass": "111111",

    "age": "29"

    }

    ]

  • 相关阅读:
    c19---指针和字符串
    c18---数组和指针
    c17---指针
    c16---字符串
    c15--二位数组
    Android -- Properties使用
    四种更新UI的方法
    Android 使用开源库StickyGridHeaders来实现带sections和headers的GridView显示本地图片效果
    Android 性能优化之使用MAT分析内存泄露
    android中PopupMenu的使用
  • 原文地址:https://www.cnblogs.com/niwalala/p/5099627.html
Copyright © 2020-2023  润新知