如何显示从ajax成功数据到html表的值?

问题描述 投票:1回答:2

我需要在我的html表中查看ajax成功消息我的cshtml代码是:

@*@{Customer.Models.Customers cust = ViewBag.Customers;
}*@
@{ 
            }

    <center><h1 style="color:red">User details</h1></center>

<div>
    <table class="table">

        <tr>
            <td>ID</td>
            <td>res.Id</td>
        </tr>
        <tr>
            <td>FIRST NAME</td>
            <td>res.Fname</td>
        </tr>
        <tr>
            <td>LAST NAME</td>
            <td>res.Lname</td>
        </tr>
        <tr>
            <td>LOCATION</td>
            <td>res.Location</td>
        </tr>
        <tr>
            <td>Contact</td>
            <td>res.Contact</td>
        </tr>
        <tr>
            <td>Email</td>
            <td>res.Email</td>
        </tr>
        <tr>
            <td>Password</td>
            <td>res.Password</td>
        </tr>
        <tr>
            <td>Role</td>
            <td>res.Category</td>
        </tr>
        <tr>

    </table>
</div>
@section Scripts{
    <script>
            $.ajax({
                contentType: "application/json",
                type: "GET",
                url: "https://localhost:44397/api/Values/Details/" + id,
                success: function (data) {
                    alert('Welcome!');
                    res = data;


                   // window.location.href = "/Home/Details/" + data.id;
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    $("#postResult").val(jqXHR.statusText);
                }
            });
    </script>
}

是否有任何方法可以使用成功数据在每个表行中传递?那就是我希望res存储成功数据,然后将其传递给诸如res.Fname之类的表字段,例如,它应该相应地显示数据。

javascript html ajax asp.net-core asp.net-ajax
2个回答
0
投票

如果您只需要在一个栏中显示值,则使用此类型


0
投票

您可以通过Ajax响应通过多种方式填充表格。在这里,您可以尝试的最易读和最受欢迎的方式。请参见下面的代码片段。

© www.soinside.com 2019 - 2024. All rights reserved.