jQuery ajax读取json文件内容

来源:互联网 发布:淘宝怎么申请企业店铺 编辑:程序博客网 时间:2024/05/19 17:25
json文件:
[{"name":"哈哈··","email":"邮箱01","gender":"男","hobby":["上网","打球"]},{"name":"呵呵··","email":"邮箱02","gender":"男","hobby":["网购","打球"]}]


js代码:

<script type="text/javascript">$(document).ready(function() {    $.ajax({//请求方式为gettype:"GET",//json文件位置url:"user.json",//返回数据格式为jsondataType: "json",//请求成功完成后要执行的方法success: function(data){//使用$.each方法遍历返回的数据date,插入到id为#result中$.each(data,function(i,item){var content=item.name+","+item.email+","+item.gender+","+item.hobby[0]+","+item.hobby[1]+"</br>";$("#result").append(content);})}})});</script>


 

原创粉丝点击