Ajax上传删除按钮

时间:2012-05-06 07:12:58

标签: jquery ajax jsp ajax-upload ajaxuploader

即时通过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>

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。我创建了一个servlet,我使用了jquery。

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