Php WP/Ajax | Jquery Dropzone js文件上传调用两次请求

Php WP/Ajax | Jquery Dropzone js文件上传调用两次请求,php,jquery,wordpress,dropzone.js,Php,Jquery,Wordpress,Dropzone.js,我使用Jquery Dropzone js进行文件上传,在服务器端PHP/WordPress上,我也看到了同样的问题,我尝试了很多方法,但仍然调用了两次文件上传请求。如果您发现我的dropzone设置有任何错误,请您帮助 我也使用这个链接中的设置:但仍然相同 jQuery(document).ready(function(jQuery){ "use strict"; jQuery.noConflict(); if(jQuery('div').is('#fvr_dropzone')){ D

我使用Jquery Dropzone js进行文件上传,在服务器端PHP/WordPress上,我也看到了同样的问题,我尝试了很多方法,但仍然调用了两次文件上传请求。如果您发现我的dropzone设置有任何错误,请您帮助

我也使用这个链接中的设置:但仍然相同

jQuery(document).ready(function(jQuery){
"use strict";
jQuery.noConflict();
if(jQuery('div').is('#fvr_dropzone')){
    Dropzone.autoDiscover = false;
}
if(jQuery('div').is('#fvr_dropzone')){
    var fvrDropZone = jQuery("#fvr_dropzone");
    var maxfile = fvrDropZone .data("max-file");
    var maxsize = fvrDropZone .data("max-size");
    var filemsg = jQuery(".dz-max-file-msg");
    var removemsg = jQuery(".dz-remove").html();
    var ourIDS = '';
    fvrDropZone .dropzone ({
        url: options.ajaxurl,
        acceptedFiles: "image/*",           
        maxFiles: maxfile,
        parallelUploads: 10,
        uploadMultiple: true,                   
        addRemoveLinks: true,
        maxFilesize: maxsize,
        dictRemoveFile: removemsg,
        autoProcessQueue: false,
        autoDiscover: false,
        init: function() {
            this.on("error", function(file, response) {
                jQuery('.dropzoneAlert').html(response);
                jQuery('.dz-max-file-msg').show();
                this.removeFile(file);
                allfile_uploaded = true;
            });
            this.on("sending", function(file, xhr, formData) {
                allfile_uploaded = false;
                formData.append("action", "fvr_media_upload");
            });
            this.on("success", function(file, response) {

                if (response.error === false) {
                     jQuery(file.previewElement).append('<input name="attachedids[]" type="hidden" value="'+ response.attachedID +'">');
                     jQuery(file.previewElement).attr("id", response.attachedID);
                }else {
                    alert(response.msg);
                    this.removeFile(file);
                }                   

            });
            this.on("complete", function(file, response) {
                jQuery('#fvr_dropzone').sortable();
                allfile_uploaded = true;
                submit_myform ();
            });
            this.on("removedfile", function(file) {
                var attachedID = jQuery(file.previewElement).attr("id");
                var attachedData = {
                    'action': 'fvr_media_upload',           
                    'delete_attached': attachedID
                };
                jQuery.ajax({
                    type : 'POST',
                    dataType : 'json',
                    url : options.ajaxurl,
                    data : attachedData,                        
                });
            });
        },
    });
}});
jQuery(文档).ready(函数)(jQuery){
“严格使用”;
jQuery.noConflict();
if(jQuery('div')。是('fvr_dropzone')){
Dropzone.autoDiscover=false;
}
if(jQuery('div')。是('fvr_dropzone')){
var fvrDropZone=jQuery(“#fvr_dropzone”);
var maxfile=fvrDropZone.data(“max文件”);
var maxsize=fvrDropZone.data(“最大大小”);
var filemsg=jQuery(“.dz max file msg”);
var removemg=jQuery(“.dz remove”).html();
var ourIDS=“”;
fvrDropZone.dropzone({
url:options.ajaxurl,
acceptedFiles:“image/*”,
maxfile:maxfile,
并行上传:10,
uploadMultiple:true,
addRemoveLinks:是的,
maxFilesize:maxsize,
dictRemoveFile:removemsg,
自动处理队列:false,
自动发现:错误,
init:function(){
此.on(“错误”,函数(文件,响应){
jQuery('.dropZoneAllert').html(响应);
jQuery('.dz max file msg').show();
此.removeFile(文件);
allfile_upload=true;
});
this.on(“发送”,函数(文件、xhr、formData){
allfile_上传=false;
formData.append(“动作”、“fvr_媒体上传”);
});
此.on(“成功”,函数(文件,响应){
if(response.error==false){
jQuery(file.previewElement).append(“”);
jQuery(file.previewElement.attr(“id”,response.attachedID);
}否则{
警报(response.msg);
此.removeFile(文件);
}                   
});
此.on(“完成”,函数(文件,响应){
jQuery('#fvr_dropzone').sortable();
allfile_upload=true;
提交我的表格();
});
此.on(“removedfile”,函数(文件){
var attachedID=jQuery(file.previewElement.attr(“id”);
var Attachedata={
“操作”:“fvr_媒体上传”,
“删除附加内容”:附加内容
};
jQuery.ajax({
键入:“POST”,
数据类型:“json”,
url:options.ajaxurl,
数据:附件,
});
});
},
});
}});
我的表格,我的Dropzone,我的按钮都在这里

<form class="form-horizontal" action="" role="form" id="primaryPostForm" method="POST" data-toggle="validator" enctype="multipart/form-data">

<!--dropzone-->
                                    <div class="dropzone dz-clickable mb-4" id="fvr_dropzone" data-max-file="<?php echo esc_attr($imageLimit ); ?>">
                                        <div class="dz-default dz-message" data-dz-message="">
                                            <p class="text-center"><i class="far fa-images fa-3x"></i></p>
                                            <span><?php esc_html_e( 'Drop files here to upload', 'fvr' ); ?></span>
                                            <span><?php esc_html_e( 'or', 'fvr' ); ?></span>
                                            <strong>
                                                <?php esc_html_e( 'Click here', 'fvr' ); ?>
                                            </strong>
                                            <span><?php esc_html_e( 'to select images', 'fvr' ); ?></span>
                                            <p class="text-muted">(<?php esc_html_e( 'Your first image will be used as a featured image, and it will be shown as thumbnail.', 'fvr' ); ?>)</p>
                                        </div>
                                        <div class="dz-max-file-msg">
                                            <div class="alert alert-danger text-center">

                                                <?php esc_html_e('You can upload', 'fvr') ?>&nbsp;<?php echo esc_attr( $imageLimit ); ?>&nbsp;<?php esc_html_e('images maximum.', 'fvr') ?>
                                            </div>
                                        </div>
                                        <div class="dz-remove" data-dz-remove>
                                            <span><?php esc_html_e('Remove', 'fvr') ?></span>
                                        </div>                              
                                    </div>

)

这就是我用js调用.processQueue()函数的方式

<script type="text/javascript">
//Check if all files uploaded
var allfile_uploaded = false;

function SubmitDonationForm (ev) {
// Upload photos first
    var myDropzone = Dropzone.forElement("#fvr_dropzone");
    myDropzone.processQueue();


}

function submit_myform () {
    if (allfile_uploaded) {
        jQuery('form#primaryPostForm').submit();
    }else {
        alert("Please wait while file uploading...")
    }
}

//检查是否已上载所有文件
var allfile_upload=false;
功能提交表单(ev){
//先上传照片
var myDropzone=Dropzone.forElement(“#fvr_Dropzone”);
myDropzone.processQueue();
}
函数提交\我的表单(){
如果(上传的所有文件){
jQuery('form#primaryPostForm').submit();
}否则{
警报(“文件上载时请稍候…”)
}
}
jQuery(文档).ready(函数)(jQuery){
“严格使用”;
jQuery.noConflict();
if(jQuery('div')。是('fvr_dropzone')){
Dropzone.autoDiscover=false;
}
if(jQuery('div')。是('fvr_dropzone')){
var fvrDropZone=jQuery(“#fvr_dropzone”);
var maxfile=fvrDropZone.data(“max文件”);
var maxsize=fvrDropZone.data(“最大大小”);
var filemsg=jQuery(“.dz max file msg”);
var removemg=jQuery(“.dz remove”).html();
var ourIDS=“”;
fvrDropZone.dropzone({
url:options.ajaxurl,
acceptedFiles:“image/*”,
maxfile:maxfile,
并行上传:10,
uploadMultiple:true,
addRemoveLinks:是的,
maxFilesize:maxsize,
dictRemoveFile:removemsg,
自动处理队列:false,
自动发现:错误,
init:function(){
此.on(“错误”,函数(文件,响应){
jQuery('.dropZoneAllert').html(响应);
jQuery('.dz max file msg').show();
此.removeFile(文件);
allfile_upload=true;
});
this.on(“发送”,函数(文件、xhr、formData){
allfile_上传=false;
formData.append(“动作”、“fvr_媒体上传”);
});
此.on(“成功”,函数(文件,响应){
if(response.error==false){
jQuery(file.previewElement).append(“”);
jQuery(file.previewElement.attr(“id”,response.attachedID);
}否则{
警报(response.msg);
此.removeFile(文件);
}                   
});
此.on(“完成”,函数(文件,响应){
jQuery('#fvr_dropzone').sortable();
allfile_upload=true;
//提交我的表格();
});
此.on(“removedfile”,函数(文件){
var attachedID=jQuery(file.previewElement.attr(“id”);
var Attachedata={
'动作':'fv
jQuery(document).ready(function(jQuery){
"use strict";
jQuery.noConflict();
if(jQuery('div').is('#fvr_dropzone')){
    Dropzone.autoDiscover = false;
}
if(jQuery('div').is('#fvr_dropzone')){
    var fvrDropZone = jQuery("#fvr_dropzone");
    var maxfile = fvrDropZone .data("max-file");
    var maxsize = fvrDropZone .data("max-size");
    var filemsg = jQuery(".dz-max-file-msg");
    var removemsg = jQuery(".dz-remove").html();
    var ourIDS = '';
    fvrDropZone .dropzone ({
        url: options.ajaxurl,
        acceptedFiles: "image/*",           
        maxFiles: maxfile,
        parallelUploads: 10,
        uploadMultiple: true,                   
        addRemoveLinks: true,
        maxFilesize: maxsize,
        dictRemoveFile: removemsg,
        autoProcessQueue: false,
        autoDiscover: false,
        init: function() {
            this.on("error", function(file, response) {
                jQuery('.dropzoneAlert').html(response);
                jQuery('.dz-max-file-msg').show();
                this.removeFile(file);
                allfile_uploaded = true;
            });
            this.on("sending", function(file, xhr, formData) {
                allfile_uploaded = false;
                formData.append("action", "fvr_media_upload");
            });
            this.on("success", function(file, response) {

                if (response.error === false) {
                     jQuery(file.previewElement).append('<input name="attachedids[]" type="hidden" value="'+ response.attachedID +'">');
                     jQuery(file.previewElement).attr("id", response.attachedID);
                }else {
                    alert(response.msg);
                    this.removeFile(file);
                }                   

            });
            this.on("complete", function(file, response) {
                jQuery('#fvr_dropzone').sortable();
                allfile_uploaded = true;
                // submit_myform();
            });
            this.on("removedfile", function(file) {
                var attachedID = jQuery(file.previewElement).attr("id");
                var attachedData = {
                    'action': 'fvr_media_upload',           
                    'delete_attached': attachedID
                };
                jQuery.ajax({
                    type : 'POST',
                    dataType : 'json',
                    url : options.ajaxurl,
                    data : attachedData,                        
                });
            });
        },
    });
}});