码迷,mamicode.com
首页 > Web开发 > 详细

Html批量读取json

时间:2016-04-12 00:08:25      阅读:514      评论:0      收藏:0      [点我收藏+]

标签:

html

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <script type="text/javascript" src="js/jquery-2.1.4.min.js"></script>
        <title></title>
    </head>
    <body>
        <script type="text/javascript">
            $.ajax({   
               type: "get",   
               url:  "DB.json", 
               datatype: "json",//"xml", "html", "script", "html", "jsonp", "text".
               success: function (data,status) {
                      document.writeln("学生:<br/>")
                       for (var x in data.student) {
                           document.writeln(data.student[x].name+data.student[x].age+"<br/>")
                       }
                       
                       document.writeln("<p/>老师:<br/>")
                       for (var x in data.teacher) {
                           document.writeln(data.teacher[x].name+data.teacher[x].age+"<br/>")
                       }
               },
               error:   function (data,status) { alert("Ajax请求Json错误");}   
             });  
        </script>
    </body>
</html>

 

 

json

{ "student": [
{ "name": "小王",  "age": "10" },
{ "name": "小丁",  "age": "20" }
],
"teacher": [
{ "name": "王老师",  "age": "30" },
{ "name": "丁老师",  "age": "40" }
] }

 

 

 

效果

技术分享

Html批量读取json

标签:

原文地址:http://www.cnblogs.com/flyings/p/5380751.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!