javascript - 为什么追加部分在ajax调用中不起作用

标签 javascript jquery asp.net-mvc

在上传文档后的下面的代码中,我编写了一个循环,该循环应该将一些图像添加到名为 Divnavigation 的分区中,但这部分不起作用。

此外,当我取消注释时,即使我的 documentViewer 也无法加载。我可以通过 AJAX 调用向我的部门添加一些内容吗?

function navigate(target) {
    $.ajax({
        url: '@Url.Action("Download", "Patient")',
        type: 'GET',
        async: true,
        dataType: 'json',
        cache: false,
        data: { 'filepath': target },
        success: function (results) {
            // documentViewer.loadDocument(results);               
            documentViewer.uploadDocumentFromUri(results[results.length -1]);
            documentViewer.addEventListener(gnostice.EventNames.afterDocumentLoad, function (eventArgs) {
                document.getElementById("TotalPage").textContent = documentViewer.viewerManager.pageCount;
                document.getElementById("pageNumber").value = documentViewer.viewerManager.currentPage;

                $("#Divnavigation").empty();
                //Get all images  with the help of model
                for (var i = 0; i < results.length; i++) {
                    $("#Divnavigation").append(" <ul> " +
                                     "<li>" +
                                     "<img src=" + results[i] + ">" + "</img>" +
                                     "<a href=" + @Url.Action("Download", "Patient") + ">" + "</a>" +
                                      "</li>"
                                + "</ul>");
                }
            });
            //showImages();
        },
        error: function () {
            alert('Error occured');
        }
    });
}

最佳答案

您好,首先回答您的问题:

我可以通过 .ajax 调用向我的部门添加一些内容吗?

您 100% 可以通过 .ajax 调用向您的部门添加内容。这是毫无疑问的。我亲自做过很多次

这次你因为其他原因没有得到。

现在我的建议是尝试使用 $("#Divnavigation").html().

官方文档:https://api.jquery.com/html/

所以首先第一步尝试放置像这样的简单html $("#Divnavigation").html("<p>test</p>)并查看是否得到输出。如果你得到然后改变,html字符串任何你想要的,这可以是硬编码的字符串,甚至你可以从操作方法中获取该字符串。

希望以上信息对您有所帮助。请分享您的想法

谢谢

关于javascript - 为什么追加部分在ajax调用中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44461150/

相关文章:

javascript - 如何在Jquery 中获取data-id 属性值?

javascript - 如何让 Apple Javascript Split Flap Counter 在纯 CSS 上运行

javascript - IE 11 中的 WebComponents 支持 - PolyFills

jquery - jqGrid:编辑时禁用表单字段

asp.net-mvc - ASP.NET MVC,在 Ajax 请求之间维护模型状态

mysql - SQL - MVC - 插入到 2 个表中

javascript - 用于水平滚动到下一个 div jQuery 的简单上一个和下一个按钮

jquery - Rails 布局中的导航栏没有响应

asp.net-mvc - Entity Framework + MVC 4 + Knockout.js AddView 模板?

javascript - Jquery, 'invalid or unexpected token'。不是字符串问题