jquery ajax请求

   $(function(){
        //  $.ajax({
        //      //方式
        //      type:"get",
        //      //地址
        //      url:"./00 data.json",
        //      data:{id:"10001"},//请求参数
        //     // data:id="id=10001&name=zhangsan", application/x-www-form-urlencoded
        //      //获取成功返回
        //      contentType:"json",//请求格式 参数的格式
        //     dataType:"json",//返回数据的格式
        //      success:function(data){
        //          console.log(data);
        //          if(data.status===200){
        //              var cls = data.data;
        //             $("legend").text(cls.name);
        //             var student = cls.student;
        //             for (let index = 0; index < student.length; index++) {
        //                 const stu = student[index];
        //              $(".data tbody").append("<tr><td>"+stu.id+"</td><td>"+stu.name+"</td></tr>");  
        //             }
        //          }else{
        //              console.log(data.msg);
        //          }
        //      },
        //      //错误返回
        //      error:function(res,err){
        //          console.log(res);
        //      }
        //  })



      //url [data] success [dataType]
         $.get("./00 data.json",function(data){
            if(data.status===200){
                     var cls = data.data;
                    $("legend").text(cls.name);
                    var student = cls.student;
                    for (let index = 0; index < student.length; index++) {
                        const stu = student[index];
                     $(".data tbody").append("<tr><td>"+stu.id+"</td><td>"+stu.name+"</td></tr>");  
                    }
                 }else{
                     console.log(data.msg);
                 }
        })
        })
posted @ 2021-11-22 11:58  六月沉  阅读(25)  评论(0)    收藏  举报