源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

jQuery使用getJSON方法获取json数据完整示例

  • 时间:2020-06-23 23:30 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:jQuery使用getJSON方法获取json数据完整示例
本文实例讲述了jQuery使用getJSON方法获取json数据。分享给大家供大家参考,具体如下: demo.js:
[
  {
    "name":"吴者然",
    "sex":"男",
    "email":"demo1@123.com"
  },
  {
    "name":"吴中者",
    "sex":"男",
    "email":"demo2@123.com"
  },
  {
    "name":"何开",
    "sex":"女",
    "email":"demo3@123.com"
  }
]

demo.html:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>getJSON获取数据</title>
<script type="text/javascript" src="js/jquery-1.10.1.min.js"></script>
<style type="text/css">
#divframe {
  border: 1px solid #999;
  width: 500px;
  margin: 0 auto;
}
.loadTitle {
  background: #CCC;
  height: 30px;
}
</style>
<script type="text/javascript">
$(function(){
  $("#btn").click(function(){
    $.getJSON("js/demo.js",function(data){
      var $jsontip = $("#jsonTip");
      var strHtml = "123";//存储数据的变量
      $jsontip.empty();//清空内容
      $.each(data,function(infoIndex,info){
        strHtml += "姓名:"+info["name"]+"<br>";
        strHtml += "性别:"+info["sex"]+"<br>";
        strHtml += "邮箱:"+info["email"]+"<br>";
        strHtml += "<hr>"
      })
      $jsontip.html(strHtml);//显示处理后的数据
    })
  })
})
</script>
</head>
<body>
<div id="divframe">
  <div class="loadTitle">
    <input type="button" value="获取数据" id="btn"/>
  </div>
  <div id="jsonTip"> </div>
</div>
</body>
</html>

效果图如下: [img]http://files.jb51.net/file_images/article/201609/2016913143052145.png?2016813143129[/img] 这里把 JSON 的后缀名改为 JS,放在 WEB 容器中则可以正常读取。 [b]PS:这里再为大家推荐几款json在线工具,相信大家在今后的开发中可以用得到:[/b] [b]在线JSON代码检验、检验、美化、格式化工具: [/b][url=http://tools.jb51.net/code/json]http://tools.jb51.net/code/json[/url] [b]JSON在线格式化工具: [/b][url=http://tools.jb51.net/code/jsonformat]http://tools.jb51.net/code/jsonformat[/url] [b]在线XML/JSON互相转换工具: [/b][url=http://tools.jb51.net/code/xmljson]http://tools.jb51.net/code/xmljson[/url] [b]json代码在线格式化/美化/压缩/编辑/转换工具: [/b][url=http://tools.jb51.net/code/jsoncodeformat]http://tools.jb51.net/code/jsoncodeformat[/url] [b]C语言风格/HTML/CSS/json代码格式化美化工具: [/b][url=http://tools.jb51.net/code/ccode_html_css_json]http://tools.jb51.net/code/ccode_html_css_json[/url] 更多关于jQuery相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/294.htm]jQuery操作json数据技巧汇总[/url]》、《[url=http://www.1sucai.cn/Special/451.htm]jQuery扩展技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/200.htm]jQuery常用插件及用法总结[/url]》、《[url=http://www.1sucai.cn/Special/497.htm]jQuery拖拽特效与技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/539.htm]jQuery表格(table)操作技巧汇总[/url]》、《[url=http://www.1sucai.cn/Special/93.htm]jquery中Ajax用法总结[/url]》、《[url=http://www.1sucai.cn/Special/430.htm]jQuery常见经典特效汇总[/url]》、《[url=http://www.1sucai.cn/Special/104.htm]jQuery动画与特效用法总结[/url]》及《[url=http://www.1sucai.cn/Special/75.htm]jquery选择器用法总结[/url]》 希望本文所述对大家jQuery程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部