Javascript 如何在上载表单并接收服务器消息后重新发送dropzone文件

Javascript 如何在上载表单并接收服务器消息后重新发送dropzone文件,javascript,forms,file-upload,dropzone.js,dropzone,Javascript,Forms,File Upload,Dropzone.js,Dropzone,我有一个表单,其中包含我使用DropZone库提交的文章信息和图像。 我对这个库没有问题,它工作得很好,但是当提交的表单出现错误时,我通过Ajax在客户端收到这个错误消息,用户修复了问题并再次发送表单,但不幸的是表单没有发送,没有留下任何文件。未选择 而这些文件在预览中可用,并且只发送到服务器一次。 我该怎么解决这个问题? 请输入简单代码。 谢谢 成功多重功能 myDropzone.on("successmultiple", function(f

我有一个表单,其中包含我使用DropZone库提交的文章信息和图像。 我对这个库没有问题,它工作得很好,但是当提交的表单出现错误时,我通过Ajax在客户端收到这个错误消息,用户修复了问题并再次发送表单,但不幸的是表单没有发送,没有留下任何文件。未选择 而这些文件在预览中可用,并且只发送到服务器一次。 我该怎么解决这个问题? 请输入简单代码。 谢谢

成功多重功能

               myDropzone.on("successmultiple", function(file,serverResponse) {

                    /* None of the uploaded files are available in Drop Zone here anymore,
                    ** and I had to delete the files so the user could choose again,
                    ** which would not be a good user experience.
                    ** Exactly what code should I write here so that there is no need to
                    ** re-select files from the user's system?
                    */
                    myDropzone.removeFile(file);

                    if(serverResponse.status)
                    {
                        // Success:: In this case, I have no problem
                        alert("Article saved successfully. Redirecting to the Articles page ...");
                        window.location.href = serverResponse.redirectedTo;
                    }
                    else
                    {
                        // Display errors received from the server to the user
                        alert("Please enter your name and resubmit the form.");
                    }
               });

我认为一个可能的解决方案是,将事件传递给successhandler,并防止它从其默认行为中发生。 像这样:

这将防止它刷新页面和丢失输入中的文件。
否则,我会将文件保存到一个变量。

我自己找到了问题的答案,我也会把它放在下面

此代码是为Laravel刀片文件编写的:

<script>
    $("document").ready(()=>{
        var path = "{{ $path }}";
        var file = new File([path], "{{ $attach->file_name }}", {type: "{{ $attach->mime_type }}", lastModified: {{ $attach->updated_at}}})
        file['status'] = "queued";
        file['status'] = "queued";
        file['previewElement'] = "div.dz-preview.dz-image-preview";
        file['previewTemplate'] = "div.dz-preview.dz-image-preview";
        file['_removeLink'] = "a.dz-remove";
        file['webkitRelativePath'] = "";
        file['width'] = 500;
        file['height'] = 500;
        file['accepted'] = true;
        file['dataURL'] = path;
        file['upload'] = {
            bytesSent: 0 ,
            filename: "{{ $attach->file_name }}" ,
            progress: 0 ,
            total: {{ $attach->file_size }} ,
            uuid: "{{ md5($attach->id) }}" ,
        };

        myDropzone.emit("addedfile", file , path);
        myDropzone.emit("thumbnail", file , path);
        // myDropzone.emit("complete", itemInfo);
        // myDropzone.options.maxFiles = myDropzone.options.maxFiles - 1;
        myDropzone.files.push(file);
        console.log(file);
    });
</script>

$(“文档”).ready(()=>{
var path=“{{$path}}”;
var file=新文件([path],“{{$attach->file_name}},{type:{{{$attach->mime_type}}”,最后修改:{{$attach->updated_at})
文件['status']=“排队”;
文件['status']=“排队”;
文件['previewElement']=“div.dz-preview.dz图像预览”;
文件['previewTemplate']=“div.dz-preview.dz图像预览”;
文件[''u removeLink']=“a.dz-remove”;
文件['webkitRelativePath']=”;
文件['width']=500;
文件['height']=500;
文件['accepted']=true;
文件['dataURL']=path;
文件['upload']={
bytesSent:0,
文件名:“{{$attach->file_name}}”,
进展:0,
总计:{{$attach->file_size},
uuid:“{md5($attach->id)}”,
};
emit(“AddFile”、文件、路径);
emit(“缩略图”、文件、路径);
//myDropzone.emit(“完成”,itemInfo);
//myDropzone.options.maxFiles=myDropzone.options.maxFiles-1;
myDropzone.files.push(文件);
console.log(文件);
});

谢谢,@Dyvd。。。它可以准确地告诉我应该写什么,应该写在哪里。你认为重新加载文件会更好吗?因为drop zone会返回Harrow文件作为响应。我只是不知道如何上传文件“Harrow”文件是什么意思?如果您想在NodeJs中上传文件,请查看文章。
<script>
    $("document").ready(()=>{
        var path = "{{ $path }}";
        var file = new File([path], "{{ $attach->file_name }}", {type: "{{ $attach->mime_type }}", lastModified: {{ $attach->updated_at}}})
        file['status'] = "queued";
        file['status'] = "queued";
        file['previewElement'] = "div.dz-preview.dz-image-preview";
        file['previewTemplate'] = "div.dz-preview.dz-image-preview";
        file['_removeLink'] = "a.dz-remove";
        file['webkitRelativePath'] = "";
        file['width'] = 500;
        file['height'] = 500;
        file['accepted'] = true;
        file['dataURL'] = path;
        file['upload'] = {
            bytesSent: 0 ,
            filename: "{{ $attach->file_name }}" ,
            progress: 0 ,
            total: {{ $attach->file_size }} ,
            uuid: "{{ md5($attach->id) }}" ,
        };

        myDropzone.emit("addedfile", file , path);
        myDropzone.emit("thumbnail", file , path);
        // myDropzone.emit("complete", itemInfo);
        // myDropzone.options.maxFiles = myDropzone.options.maxFiles - 1;
        myDropzone.files.push(file);
        console.log(file);
    });
</script>