2012-05-06 2 views
1

메신저 jsp로 업로드하는 중입니다. 그것은 잘 작동하지만 각 파일에 대한 또는 적어도 모든 파일에 대한 삭제 버튼을 추가하고 싶습니다. 이것은 내 코드입니다.Ajax 업로드 삭제 버튼

<script type="text/javascript"> 
    $(function() { 
     var btnUpload = $('#upload'); 
     var status = $('#status'); 
     new AjaxUpload(btnUpload, { 
      action: 'uploadServlet', 
      name: 'uploadfile', 
      onSubmit: function (file, ext) { 
       if (!(ext && /^(jpg|png|jpeg|gif)$/.test(ext))) { 
        // extension is not allowed 
        status.text('Only JPG, PNG or GIF files are allowed'); 
        return false; 
       } 
       status.text('Uploading...'); 
      }, 
      onComplete: function (file, response) { 
       //On completion clear the status 
       status.text(''); 
       $('<li></li>').appendTo('#files').html('<img src="./uploads/' + file + '" alt="" height="40" width="40"/><br />' + file).addClass('success'); 

      } 
     }); 

    }); 
</script> 

<div id="mainbody"> 
    <h3>&raquo; AJAX File Upload Form Using jQuery</h3> 
    <!-- Upload Button, use 
    any id you wish--> 
    <div id="upload"> 
     <span>Upload File 
      <span> 
    </div> 
    <span id="status"></span> 
    <ul id="files"></ul> 
</div> 
+0

어떻게 작동하는지 잘못 이해하고 있습니다. 클라이언트 측 코드를 사용하여 서버에서 파일을 삭제할 수 없습니다. –

+0

나는 실수로 파일을 업로드하고 그 파일을 삭제 (취소)하고 다른 파일을 업로드하고 싶습니다. 어떻게해야합니까?! 그래서, 나는 잘못된 파일을 삭제하기 위해 클라이언트에 다른 버튼을 추가하기를 원합니다. 내가 어떻게 ajaxupload 그것을 할 수 있습니다. – Baimd

+0

파일을 삭제하는 서버 메소드를 호출하는 삭제 버튼을 추가하십시오. 이 버튼에는 ajax 기능이 있습니다. –

답변

0

해결책을 찾았습니다. 서블릿을 만들고 jquery를 사용했습니다.

    $('ul').on("click","#delete",function(){      
       var del=$(this).parent(); 
       $filename = del.text();     
       del.fadeOut('slow', function() { del.remove(); }); 
       $.post("deleteServlet", {filename:$filename}, function() {}); 
      });