猿问

Dropzone 手动删除上传的文件

我正在构建一个dropzone用于上传文件的表单。我可以轻松上传文件。我还添加了一个选项来删除上传的文件,使用 ,


addRemoveLinks: true

但它仅删除预览窗格中的文件,而不是存储文件的服务器中的文件。有没有办法在 dropzone 中编写手动 ajax 请求以删除 dropzone 中的上传文件?我的刀片文件包含 dropzone 。



<div class="col-md-3 text-center">

                <label class="checkbox-inline"><input type="checkbox" name = "RC" id = "RC" value="RC">RC</label>

                <div class="dropzone" id="dropzoneFileUpload">

                  <label for="file" class="control-label text-center">Choose a file</label>

                  <span class="control-fileupload">   

                    <img src="{{URL::asset('/images/image_upload.svg')}}" width="50px" class="upload-icon">

                  </span>

                </div>

                <div class="deleteRC" id = "deleteRC">

                  <button type ="button" class="btn btn-danger" style="cursor:'pointer';" onclick = "Deleteimg();" data-toggle="tooltip" data-placement="top" title="Delete"><span class="glyphicon glyphicon-trash"></span></button>

                </div>

              </div>


<script type="text/javascript">

var baseUrl = "{{ url('/') }}";

        var token = "{{ csrf_token() }}";

        var documentType = $("#RC").val();

        Dropzone.autoDiscover = false;

        var myDropzone = new Dropzone("div#dropzoneFileUpload", {

            url: baseUrl + "/dropzone/uploadImage",

            addRemoveLinks: true,

            params: {

                _token: token,

                documentType: documentType

            },

            success:function(file, response)

            {

              doctype = doctype.concat(response['documentType']);

              $("#documentType").val(doctype);

              doc = doc.concat(response['doc']);

              $("#document").val(doc);

              alert("Upload completed");

              //document.getElementById("deleteRC").style.display = "block";

            },

        }

        });

</script>


慕斯王
浏览 320回答 1
1回答

噜噜哒

您可以使用 removedfile 选项,您可以在从列表中删除文件后调用该选项addRemoveLinks: true,removedfile: function(file) {&nbsp; &nbsp; var name = file.name;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; $.ajax({&nbsp; &nbsp; &nbsp; &nbsp; type: 'POST',&nbsp; &nbsp; &nbsp; &nbsp; url: 'url.php',&nbsp; &nbsp; &nbsp; &nbsp; data: "id="+name,&nbsp; &nbsp; &nbsp; &nbsp; dataType: 'html'&nbsp; &nbsp; });var _del;return (_del= file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
随时随地看视频慕课网APP
我要回答