How to check images are added in dropzone before posting ajax properly?

131 Views Asked by At

I've attempted to write a script to check if there was any images dropped on dropzone. I'm using twitter bootstrap.

The ajax script that runs on submit is:

$.ajax({
    type: method,
    action: action,
    data: formdata,
    processData: false,
    contentType: false,
    dataType: 'json',
    beforeSend: function(xhr) {
        if (myDropzone.getQueuedFiles().length == 0) {
            // I've managed to get the values of the number of images dropped.
            // I want to inform the user that they've not added any images,
            // They can continue to submit without adding images if they click on continue on the modal
            // Or click cancel and drop some images.
        }
    },
    success: function(data) {
        console.log(data);
    },
    error: function(data) {
        var errors = data.responseJSON;
            console.log(data);
            $.each(errors, function(key, value) {
                $('#' + key).after('<div class="alert alert-danger">' + value + '</div>');
            });
    }

});

I'm not sure how to achieve that. Thank you for reading

0

There are 0 best solutions below