在上传文档后的下面的代码中,我编写了一个循环,该循环应该将一些图像添加到名为 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/