遍历HTML表并使用AJAX GET更新值

时间:2019-05-02 14:09:03

标签: jquery ajax

我在ASP.NET Core MVC中构建了一个小应用程序,您可以在其中选择一个货件,它将遍历blob存储中的所有图像并将其显示在网页中。需要加载网页,然后加载图片,因为这可能是一个沉重的负担。

下面是我拥有的HTML-

<table id="ImageTable">
        <tr>
        <th>
            Img
        </th>
        </tr>
        <tr>
            @foreach (var shipment in Model.shipmentImages)
            {
                <td class="ImageCell">@shipment.RowKey</td>
            }
        </tr>
    </table>

下面是AJAX,它在调试时似乎可以正常运行,只是网页没有更新。

@section Scripts {
<script type="text/javascript">
$('#ImageTable td.ImageCell').each(function () {
        var cellItem = $(this);
        console.log(cellItem.html);
        console.log(cellItem);
        $.ajax({
            url: 'https://localhost:5001/Shipment/GetImage?' + $(this).html(),
            type: 'GET',
            success: function (data) {
                console.log($(this.html));
                console.log(data);
                cellItem.append(data.html);
            }
    });
});
    </script>
}

我可以在控制台中看到,我要查找的HTML数据已返回,但是表中的单元格不会使用新的HTML更新。

谢谢

1 个答案:

答案 0 :(得分:0)

原来的问题是使用.html。下面解决了该问题-

@section Scripts {
<script type="text/javascript">
$('#ImageTable td.ImageCell').each(function () {
        var cellItem = $(this);
        $.ajax({
            url: 'https://localhost:5001/Shipment/GetImage?' + $(this).html(),
            type: 'GET',
            success: function (data) {
                cellItem.append(data);
            }
    });
});
    </script>
}
相关问题