繁体   English   中英

上传内容后刷新引导模式对话框的主体

[英]Refresh body of bootstrap modal dialog after uploading something

我正在创建一个服务,我通过引导模式对话框更改数据库中的一些数据。 上传文件后,我在模态对话框正文中显示了这个名称。 但是我看不到我刚刚上传的文件的名称,我必须关闭对话框然后再次打开它,没有它我无法看到上传文件的实际名称。

问题是:如何在不关闭它的情况下刷新模态对话框的“模态主体”?

这是我的模态html:

<div class="modal fade" id="editModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content" style="width: 535px">
        <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLongTitle">Edit Event</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
            </button>
        </div>
        <div class="modal-body">

            <div id="dialog-edit"></div>
            <div id="EditStatus"></div>
            
        </div>
    </div>
</div>

和我的 javascript:

tab.on("click", ".btnUpload", function (e) {

        var formData = new FormData();
        var id = $(this).closest("tr").find('#fileId').text();
        var file = document.getElementById("FileUpload").files[0];
        formData.append("id", id);
        formData.append("file", file);

        

        $.ajax({
            type: "POST",
            url: "/Events/UpdateJsionFile",
            contentType: false,
            processData: false,
            dataType: "JSON",
            data: formData,
            success: function (data) {
                if (!data.success) {

                    var res = $('<div style="color:red;">' + data.error + '</div>')
                    $('#uploadStatus').html(res);
                    
                }
                else {

                    $('#uploadStatus').html("File #1 uploaded!");
                    
                }
            }

            });


    });

一切正常,但我不知道上传后如何刷新数据? 有人可以帮我吗?

我是这样解决的:

首先,我创建了一个带有文件名的变量:

var fileName = document.getElementById("FileUpload").files(0).name;

然后,在我的 ajax 成功之后:

$('.FileUpload').html(fileName);

希望它会帮助那些正在寻找同样东西的人......

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM