// 先判断是否是200
// 获取数据
// 返回数据
// var students=cls.student; // for (let index = 0; index < students.length; index++) { // const stu = students[index]; // $(".data tbody").append("<tr><td>"+stu.id+"</td><td>"+stu.name+"</td></tr>"); // } // }else{ // console.log(data.msg); // } // }, // error:function(res){ // console.log(res); // } // }) }) 还可以用另一种方法: <script> $(function(){ $.get("./data.json",function(data){ if(data.status===200){ var cls=data.data; $("legend").text(cls.name);
var students=cls.student; for (let index = 0; index < students.length; index++) { const stu = students[index]; $(".data tbody").append("<tr><td>"+stu.id+"</td><td>"+stu.name+"</td></tr>"); } }else{ console.log(data.msg); } }) //url [data] success [dataType] //$.post() }) 最后显示内容 body的内容: <legend></legend> <table class="data"> <thead> <td>id</td> <td>name</td> </thead> <tbody> <!-- <tr></tr> --> </tbody> </table> <legend></legend> <table class="data"> <thead> <td>id</td> <td>name</td> </thead> <tbody> <!-- <tr></tr> --> </tbody> </table>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。