0

I have attachment form with dropzonejs file upload and note field and need to send those both fields data to my server on jQuery AJAX form submit.

Attachment HTML Form code

<form id="addAttachmentForm" method="post" enctype="multipart/form-data" novalidate="novalidate">
<div class="modal-body">
    <div class="companyAttachment box__input dz-clickable"
    </div>
    <textarea class="form-control resizeNone" name="Note" placeholder="Your note here" rows="5"></textarea>
</div>
<div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
    <button type="submit" class="btn btn-primary btn-Attachment" id="add-attachment">ADD ATTACHMENT</button>
</div>

JS Code

$(document).on('submit', '#addAttachmentForm',function(e) {
e.preventDefault();
    $.ajax({
        type: 'POST',
        url: '/attachment/store',
        data: new FormData(this),
        contentType: false,
        cache: false,
        processData:false,
        beforeSend: function () {
        },
        success: function(response)
        {
            // contactDropzone.processQueue();
        },
        error: function (data) {
        }
    });});

Dropzone.autoDiscover = false;
var contactDropzone = $('.companyAttachment').dropzone({
   url: null,
   paramName: 'file',
   addRemoveLinks: true,
   maxFiles: 1,
   autoProcessQueue: false,
   maxFilesize: 2,
   acceptedFiles: 'image/*,application/pdf',
   init: function(){
       this.on("addedfile", function(file, data) {
       });
   }});

I set the default value of autoProcessQueue is false, but I'm confused about when I need to call contactDropzone.processQueue() method to work for AJAX form submission? or please suggest me any other better ways to POST attachment and note fields data on jQuery AJAX form submission.

ranjit redekar
  • 919
  • 1
  • 12
  • 24
  • [This answer might help](https://stackoverflow.com/questions/46728205/dropzone-submit-button-on-upload/46732882#46732882). – Don't Panic Nov 25 '18 at 15:13
  • Thanks @Don'tPanic for your sharing this resolve my problem when I have one dropzonejs object but I have another scenario with multiple dropzonejs object like image upload and document upload. so, how I need to achive this with single asyn request? – ranjit redekar Nov 26 '18 at 08:44
  • 1
    Happy to help. If the linked answer helped, please upvote it. If you have a new question, either edit this question with your new details or post a new question. – Don't Panic Nov 29 '18 at 13:19

0 Answers0