使用Ajax请求上传文件后,Div标签未刷新

我正在尝试在C#MVC应用程序中上传文件,并希望在使用ajax method上传后立即显示文件名。它会绑定文件名,但不会立即显示名称,但是当我刷新页面时,它正在加载文件名。

<div id="refreshFiles">
    <input type="file" name="fileUpload" id="fileUpload" size="23" multiple /><br />
    <button>Upload</button>
    </form>*@
    <input type="file" id="FileUpload1" multiple />
    <input type="button" id="btnUpload" value="Upload Files" onclick="FileUploadd()" />
    <div>
      @if (Session["fileUploader"] != null) 
      {
        <div class="upload">
          <div style="width: 500px;">
            <table id="uloadTable" border="1">
              <thead>
                <tr>
                  <th>Name</th>
                  <th>action</th>
                </tr>
              </thead>
              <tbody name="bodyfiles">
                @foreach (var item in (List<UL.RADAR.ViewModel.FileUploadmodel>)Session["fileUploader"]) 
                {
                  <tr id="@item.FileName">
                    <td>@item.FileName</td>
                    <td style="text-align: center">
                      <a class="viewc" href="@Url.action(" OpenFile ","FileUpload ",new { @fileName = item.FileName })">
                        <img width="16" height="16" border="0" src="~/Images/view.png" class="viewc">
                      </a>
                      <a class="viewc" href="">
                        <img width="16" height="16" border="0" src="~/Images/Delete.png" class="link">
                      </a>
                    </td>
                  </tr>
                }
              </tbody>
            </table>
          </div>
        </div>
      }
    </div>
  @*end*@
</div>
function FileUploadd() {
  if (window.FormData !== undefined) {
    var fileUpload = $("#FileUpload1").get(0);
    var files = fileUpload.files;
    var fileData = new FormData();

    for (var i = 0; i < files.length; i++) {
      fileData.append(files[i].name,files[i]);
    }
    //fileData.append('username',‘Manas’);

    $.ajax({
      url: '/RequirementManagement/FilesUpload',type: "POST",contentType: false,// Not to set any content header
      processData: false,// Not to process data
      data: fileData,success: function(result) {
        $.get(location.href).then(function(page) {          $("#refreshFiles").html($(page).find("#refreshFiles").html())
        })
      },error: function(err) {
        alert(err.statusText);
      }
    });
  } else {
    alert("FormData is not supported.");
  }
};
shinyzhuzhu 回答:使用Ajax请求上传文件后,Div标签未刷新

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3110367.html

大家都在问