DropZonejs: Submit form without files

后端 未结 7 1777
一生所求
一生所求 2020-12-05 14:27

I\'ve successfully integrated dropzone.js inside an existing form. This form posts the attachments and other inputs like checkboxes, etc.

When I submit the form wit

7条回答
  •  执念已碎
    2020-12-05 14:46

    The first approach is kind of too expensive for me, I would not like to dive into the source code and modify it,

    If you happen to be like me , use this.

    function submitMyFormWithData(url)
        {
            formData = new FormData();
            //formData.append('nameOfInputField', $('input[name="nameOfInputField"]').val() );
    
            $.ajax({
                    url: url,
                    data: formData,
                    processData: false,
                    contentType: false,
                    type: 'POST',
    
                    success: function(data){
                    alert(data);
                    }
            });
        }
    

    And in your dropzone script

    $("#submit").on("click", function(e) {
                          // Make sure that the form isn't actually being sent.
                          e.preventDefault();
                          e.stopPropagation();
    
                            if (myDropzone.getQueuedFiles().length > 0)
                            {                        
                                    myDropzone.processQueue();  
                            } else {                 
                                    submitMyFormWithData(ajaxURL);
                            }     
    
                        });
    

提交回复
热议问题