<?php if ($block->isReturnInStoreEnabled()): ?>
<script type="text/javascript">
    require([
        "jquery",
        'mage/url',
        "mage/mage"
    ],function($, url) {
        $(document).ready(function() {
            $('#rma_create_form').mage(
                'validation',
                {
                    submitHandler: function(form) {

                        var formAction = $(form).attr('action') + "ajax/true";
                        $('body').trigger('processStart');
                        $.ajax({
                            url: formAction,
                            data: $('#rma_create_form').serialize(),
                            type: 'POST',
                            dataType: 'json',
                            showLoader: true,
                            beforeSend: function() {
                                // show some loading icon
                            },
                            success: function(data, status, xhr) {
                                // data contains your controller response
                                var linkUrl = url.build('rma/returns/history');
                                window.location.href = linkUrl;
                                $('body').trigger('processStop');

                            },
                            error: function (xhr, status, errorThrown) {
                                var linkUrl = url.build('rma/returns/history');
                                window.location.href = linkUrl;
                                $('body').trigger('processStop');
                            }
                        }).done(function (data) {

                            return true;
                        });
                    }
                }
            );
        });
    });
</script>
<?php endif; ?>