<script>
$("document").ready(function() {
    $("[data-form-role='bulk-upload']").submit(function(e) {
        e.preventDefault();
        var formData = new FormData($(this)[0]);
        let errorDiv = $(this).data('error-div');
        $(errorDiv).html('');

        $.ajax({
            type: "POST",
            url: $(this).attr('action'),
            data: formData,
            processData: false,
            contentType: false,
            success: function(response) {
                window.location.reload();
            },
            error: function(xhr, status, error) {
                let response = xhr.responseJSON;

                if(response.errors) {
                    $(errorDiv).html(response.errors);
                }
            }
        });
    });
});
</script>