Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/435.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Dropzone功能成功_Javascript_Jquery_Html_Dropzone.js - Fatal编程技术网

Javascript Dropzone功能成功

Javascript Dropzone功能成功,javascript,jquery,html,dropzone.js,Javascript,Jquery,Html,Dropzone.js,我有这个密码 代码JS var addedFiles = []; Dropzone.autoDiscover = false; var myDropzone = new Dropzone("div#myDrop", { url : "<?php echo $this->serverUrl() . '/profile/ajax/dzupload'; ?>", paramName : 'patie

我有这个密码

代码JS

var addedFiles = [];

    Dropzone.autoDiscover = false;
    var myDropzone = new Dropzone("div#myDrop", {
        url             : "<?php echo $this->serverUrl() . '/profile/ajax/dzupload'; ?>",
        paramName       : 'patientfile',
        acceptedFiles   : "image/*",
        maxFiles        : 10,
        parallelUploads : 10,
        addRemoveLinks  : true,
        autoProcessQueue: false,
        uploadMultiple  : true,

        accept : function(file, done){
            // we reject files with the same name on the same upload
            if($.inArray(file.name,addedFiles) >= 0 ) {
                // if file is already in the list we return done() with a message in order to
                // notify the user that he cannot upload it and also prevent if from uploading
                done("File with the same name cannot be uploaded");
            } else {
                // if the file is ok, we add it it's name to the list for further validation
                addedFiles.push(file.name);
                return done();
            }

        },

        init : function() {
            this.on("addedfile", function(file) {
                //console.log(this.addedFiles);
            });

            // on click on either of the two "Save" buttons we send the files to be processed on backend
            $('[id^=savePatientFiles_]').click(function(e){
                e.preventDefault();
                myDropzone.processQueue();
            });

            this.on('sending', function(file, xhr, formData){
                formData.append("patientId", "<?php echo $this->pacientInfo->id ?>");
            });

            this.on("success", function(file, responseText) {
                // from backend a response will be returned for every file uploaded 

                alert("test");   //This alert is performed twice for each added file

                // console.log(file);
                var responseSuccess = [];
                // console.log(responseText);
                $.each(responseText, function( index, value ) {
                //  console.log(value.succes);
                    responseSuccess.push(value.success );
                    console.log(responseText);
                //  window.location.href = 'your_url';
                });

                if ($.inArray(false,responseSuccess) == -1){
                    var url_redirect = "<?php echo $this->serverUrl().str_replace('public','',$this->basePath()).'/user/viewfilesforpatient/'.$this->pacientInfo->id; ?>"
                    window.location.href = url_redirect;
                    // TODO: if false is not returned, redirect the user to the page where he can see the files
                } else {

                    // TODO: append error messages inside the page to warn the user what was wrong
                }

            });

            this.on("maxfilesexceeded", function(file){
                this.removeFile(file);
                alert("You are not allowed to chose more than 10 file!");
            });
        }
    });
这样做的原因是什么?如何将每个文件的执行限制为一次

提前谢谢

编辑:

我试图伪造我的问题代码笔,但我们做到了。。
此警报对每个文件执行一次

是否可以创建一个FIDDLE?这两个保存按钮是否定义为提交按钮?是的……这就是问题所在
If I upload 1 file --- `alert()`--two executions
If I upload 2 file --- `alert()`--four executions

----- and so on