【问题标题】:Display Data from ajax Json to ul tag in web forms asp.net在 web 表单 asp.net 中显示从 ajax Json 到 ul 标记的数据
【发布时间】:2020-10-25 13:25:59
【问题描述】:

我有这个函数可以使用 JSON 从数据库中获取数据

    function BindMembers() {
            $.ajax({
                url: "/test.asmx/test1",
                type: "GET",
                dataType: "json",
                contentType: "application/Json; Charset= Utf-8",
                success: function (data) {
                    var list = "";
                    $.each(data.data, function (index, item) {
                        list += "<li class='text-secondary p-1'><a class='btn-link text-secondary'><b>" + item.Id + "</b>" + ", " + "<span class='font-italic'><small>" + item.Id + "</small></span><small><a href='#' Onclick='Delete(" + item.Id + ")'> <i class='float-right far fa-trash-alt'></i></a></small></a>" + "</li>";
                    });
                    $("#list").html(list);
                },
                error: function (response) {
                    alert(response);
                }
            });
        }

这是我的 HTML 代码:

    <ul id="list">
       <li></li>
    </ul>

我需要从函数中绑定&lt;div&gt;标签。

有人有什么建议吗?

【问题讨论】:

    标签: javascript jquery asp.net json xmlhttprequest


    【解决方案1】:

    更新:

    更改为 an,因为
  • 只能添加到
      ,如 https://developer.mozilla.org/en-US/docs/Web/HTML/Element/li
  • 【讨论】:

    • 我需要通过这个函数BindMembers()在我的html中绑定标签div
    • 对不起,你的 HTML 中不是已经有 div 了吗?因此,将其填充到您所做的函数中也应该将其呈现为 HTML。我的问题是数据没有出现吗?也许将 div 更改为
    猜你喜欢
    相关资源
    最近更新 更多
    热门标签