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

get获取Json

时间:2016-04-10 16:11:38      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:

前端代码

<!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>
        <div >
            小丁的年龄是:<span id="dsh"></span>
        </div>
        <script type="text/javascript">
            $.ajax({   
            type: "get",   
              url:  "DB.json", 
              datatype: "json",//"xml", "html", "script", "html", "jsonp", "text".
               success: function (data,status) {
                   document.getElementById("dsh").innerHTML=data.teacher[1].age;
                   //var js=JSON.stringify(data);//转换成json字符串
               },
               error:   function (data,status) { alert("Ajax请求Json错误");}   
             });  
        </script>
    </body>
</html>

 

 

DB.json

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

 

 

效果

技术分享

get获取Json

标签:

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

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