Fork me on GitHub

ajax取json数据——简单的

 

json数据:json4.json

 

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
    </head>
    <body>
        <table>
            <tbody id="tbody1"></tbody>
        </table>
    </body>
    <script src="js/jquery-1.8.3.min.js"></script>
    <script>
        $(function(){
            $.ajax({
                type:"get",
                url:"js/json4.json",
                dataType:'json',
                success:function(ret){
                    console.log(ret.data);
                    var data  = ret.data.items;
                    var totalsize = ret.data.totalsize;
                    var html = '';
                     for(var i=0;i<totalsize;i++)
                        {
                            html+="<tr>"    
                                +"<td>"+data[i]['classId']+"</td>"
                                +"<td>"+data[i]['fullName']+"</td>"
                                +"<td>"+data[i]['groupName']+"</td>"
                                +"<td>"+data[i]['name']+"</td>"
                                +"<td>"+data[i]['number']+"</td>"
                                +"</tr>"
                        }
                      $("#tbody1").html(html);
                },
                error:function(){
                    
                }
            });
            
        })
    </script>
</html>

 

  

posted on 2015-01-22 14:10  雨为我停  阅读(235)  评论(0编辑  收藏  举报