简体   繁体   English

上传后用Javascript刷新页面

[英]Refreshing Page with Javascript after upload

I have an upload form on the page. 我在页面上有一个上传表单。 After it submits it doesn't fully refresh the page. 提交后,它不会完全刷新页面。 It breaks my datatable because it isn't fully refreshing but still putting the new file in the datatable. 它破坏了我的数据表,因为它没有完全刷新,但仍将新文件放入数据表中。 How can I refresh the page completely after upload? 上传后如何完全刷新页面?

$('#FileContents').on('filebatchuploadcomplete', function(event, files, extra) {
        $("#addfilemodal").modal("hide");
        $("#filesuccess").show();
        var fileCount = parseInt($("#filecount").text());
        fileCount += 1;
        $("#filecount").html(fileCount);

        $("#filebody").load("@Url.Action("Attachments", new {collaborationId = Model.Collaboration.Id})");
    });

You don't need to refresh page. 您不需要刷新页面。

Add callback to load. 添加回调以加载。 In callback initialize/apply your js library (for controlling datatable). 在回调中初始化/应用您的js库(用于控制数据表)。

 $("#filebody").load("@Url.Action("Attachments", new {collaborationId = Model.Collaboration.Id})");

to

$("#filebody").load("@Url.Action("Attachments", new {collaborationId = Model.Collaboration.Id})", function( response, status, xhr ) {
 //Apply Datatable js library in here
});

Because you are removing elements at #filebody and adding new elements. 因为您要删除#filebody上的元素并添加新元素。 So you should apply your js library to the new elements. 因此,您应该将js库应用于新元素。

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

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