2016-09-07 2 views
0

우리는 C#, js, jquery로 하나의 호출기 웹 사이트를 만들었습니다. 업로드를 위해 C# 컨트롤러를 호출하는 정상적인 업로드 양식이 있습니다. 업로드가 동일한 창이 완료되면 새로 고쳐지고 모든 파일 목록에 새 파일이 표시됩니다.같은 이름의 jQuery 파일 업로드가 작동하지 않습니다.

사용자가 파일에 오류가 있음을 알게되고 파일을 다시 업로드 할 수 있습니다. 페이지가 리 레이드되지 않으면 파일을 업로드 할 수 없습니다. 내 triger 기능이 더 이상 작동하지 않습니다.

수동으로 페이지를 새로 고치지 않고 정확히 동일한 이름으로 파일을 두 번 업로드 할 수 있습니까?

내 업로드 트리거 기능

// formUploadRisk-Formular open 
 
    $("#uploadRiskPolicyFile").change(function() { 
 
     if (confirm("Would you like to upload the file?")) { 
 
      var riskId = $(managementRiskPdfMenu).data("riskId"); 
 
      var control = document.getElementById("uploadRiskPolicyFile"); 
 
      var files = control.files[0]; 
 
      var success = UploadRiskPdf(riskId, 1, files); 
 
      if (success) { 
 
       LoadManagementPdfMenu(riskId); 
 
      } 
 
      return false; 
 
     } 
 
    });

내 uploadfunction

function UploadRiskPdf(riskId, documentTypeID, files) { 
 

 
    var result = false; 
 

 
    // Methode to save 
 
    var fd = new FormData(); 
 

 
    fd.append('file', files); 
 

 
    var uploadURL = "documents/upload/risk/" + riskId + "/" + documentTypeID; 
 

 
    var jqXHR = $.ajax({ 
 
     xhr: function() { 
 
      return $.ajaxSettings.xhr(); 
 
     }, 
 
     url: uploadURL, 
 
     type: "POST", 
 
     async: false, 
 
     enctype: 'multipart/form-data', 
 
     contentType: false, 
 
     cache: false, 
 
     processData: false, 
 
     data: fd, 
 
     success: function (response) { 
 
      var node 
 
      result = true; 
 
      var d = data; 
 
     }, 
 
     error: function (data) { 
 
      alert("Some error!") 
 
     } 
 
    }); 
 

 
    return result; 
 
}
내 HTML을 appendet 것입니다 리 KE이

var documentRow = $.parseHTML('<div><span><a class="risikoPdf" href="documents/customer/' + value.DocumentID + '" target="_blank"><i style="margin-right:5px;" class="fa fa-file-pdf-o fa-2x"></i>' + value.UploadDate + '_' + value.ProgramCode + '</a></span><span class="document-edit-delete fa fa-trash fa-2x"></span></div>'); 
 

 

 
$("#" + layoutId).append(documentRow); 
 
       

내 HTML은

<div id="uploadPdfDocumentPolicy" class="uploaderRisiko"> 
 
       <div class="browser"> 
 
        <label> 
 
         <span>Policen</span> 
 
         <input id="uploadRiskPolicyFile" class="fa fa-plus-circle fa-lg" type="file" name="FileUploadPolicy" title="Klicken, um eine weitere Rechnung hochzuladen" /> 
 
         <i class="fa fa-plus-circle fa-lg"></i> 
 
        </label> 
 
       </div> 
 
      </div> 
 
      <div id="uploadPdfDocumentBill" class="uploaderRisiko"> 
 
       <div class="browser"> 
 
        <label> 
 
         <span>Rechnungen</span> 
 
         <input id="uploadRiskBillFile" class="fa fa-plus-circle fa-lg" type="file" name="FileUploadBill" title="Klicken, um eine weitere Rechnung hochzuladen" /> 
 
         <i class="fa fa-plus-circle fa-lg"></i> 
 
        </label> 
 
       </div> 
 
      </div>

답변

0

나는 내 문제를 해결했다.

값이 비어 있는지 확인하는 검사기 변수를 만들었습니다. succsess 후 입력 필드의 값을 지 웁니다. 왜냐하면 이것은 JS 변경 함수에 대한 변경이기 때문에이 함수에 다시 올 것이다. 왜냐하면 statment 인 경우 왜 ckecker가 필요한가.

$("#uploadRiskPolicyFile").change(function() { 
 
     var checker = $("input[name='FileUploadPolicy']").val(); 
 
     if (checker != '') { 
 
      if (confirm("Willst du das File hochladen?")) { 
 
       var riskId = $(managementRiskPdfMenu).data("riskId"); 
 
       var control = document.getElementById("uploadRiskPolicyFile"); 
 
       var files = control.files[0]; 
 

 
       var success = UploadRiskPdf(riskId, 1, files); 
 
       if (success) { 
 
        LoadManagementPdfMenu(riskId); 
 
        $("input[name='FileUploadPolicy']").val(''); 
 
       } 
 
      } 
 
     } 
 
    });

관련 문제