我的账户
猩码学苑

专注C++开发菁英教育

亲爱的游客,欢迎!

已有账号,请

如尚未注册?

王龙飞 2023-1-06

[复制链接]
浅夏ζ 发表于 2023-2-16 18:16:07 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
<body>
    <table>
      <thead>
        <tr>
          <th>id</th>
          <th>姓名</th>
          <th>年龄</th>
          <th>性别</th>
          <th>电话</th>
          <!-- <th></th> -->
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>1</td>
          <td>2</td>
          <td>3</td>
          <td>4</td>
          <td>5</td>
        </tr>
      </tbody>
    </table>
    <script>
      function renderlist() {
        //发送ajax--接收响应数据

        var xhr = new XMLHttpRequest();
        // xhr.open("get", "http://162.14.107.109/list");
        xhr.open("post", "http://162.14.107.109/list");
        xhr.send();

        //监听事件--onr eadystatechange
        xhr.onreadystatechange = function () {
          if (xhr.readyState == 4) {
            console.log(JSON.parse(xhr.responseText));
            // document.querySelector('tbody')
            // console.log();
            let stuList = JSON.parse(xhr.responseText).data.data;
            //
            let html = "";
            stuList.forEach((v) => {
            //   console.log(v);
              html += `
                        <tr>
                <td>${v.id}</td>
                <td>${v.name}</td>
                <td>${v.age}</td>
                <td>${v.sex}</td>
                <td>${v.tel}</td>
            </tr>`;
            });
            document.querySelector('tbody').innerHTML=html
          }
        };

        //tbody中渲染
      }
      renderlist();
    </script>

回复

使用道具 举报

关注0

粉丝0

帖子76

发布主题
大家都在学
课堂讨论
一周热帖排行最近7x24小时热帖
关注我们
专注C++菁英教育

客服电话:18009298968

客服时间:9:00-21:00

猩码学苑 - 专注C++开发菁英教育!( 陕ICP备2025058934号-1 )

版权所有 © 陕西菁英数字科技有限公司 2023-2026