ajax从服务器获取信息并拼接显示在table

1、页面代码

<body>
    <h1>显示所有员工信息</h1>
    <div>
        <table class="table">
            @*标题*@
            <thead>
                <tr>
                    <th>账号</th>
                    <th>真实姓名</th>
                    <th>电话</th>
                    <th>密码</th>
                    <th>状态</th>
                </tr>
            </thead>
            @*内容*@
            <tbody id="tbd"></tbody>
        </table>
    </div>
</body>

2、ajax

<script>
    //文档准备就绪函数
    $(function () {
        lists();
    })
    //显示信息
    function lists() {
        $.ajax({
            url: "http://localhost:51071/api/User",
            type: "get",
            success: function (data) {
                //清空tbd
                $("#tbd").empty();
                for (var item in data) {
                    //进行拼接
                    $("#tbd").append(
                        "<tr>" +
                        //依次获取各字段
                        "<th>" + data[item].Name + "</th>" +
                        "<th>" + data[item].RealName + "</th>" +
                        "<th>" + data[item].Telphone + "</th>" +
                        "<th>" + data[item].Pass + "</th>" +
                        "<th>" + data[item].Status + "</th>" +
                        "</tr>");
                }
            }
        });
    }
</script>