1

im using ajax upload with jsp. it's work well but I wanna add delete button for each file or at least for all files. this is my code:

<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>
Milap
  • 6,915
  • 8
  • 26
  • 46
Baimd
  • 13
  • 5
  • Methinks you misunderstand how this works. You can't delete a file on the server with client side code. – Spencer Ruport May 06 '12 at 07:19
  • I mean that some one uploads file by a mistake and he wanna delete(cancel) it and upload another file,what should he do?! So, I wanna just add another button for the client to delete the wrong file. how i can do it by ajaxupload. – Baimd May 06 '12 at 09:13
  • Add a Delete button that calls a server method that delete the file(s). This button can also has an ajax functionality. – Luiggi Mendoza May 06 '12 at 15:57

1 Answers1

0

I found the solution. I created a servlet and i used jquery.

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