0

I have a code by which I add information to a database and display it on the same page where the form is (using AJAX), but after refreshing the page, the data disappears (in the database they are) How to keep this information on one page. All this should be implemented with the AJAX.   P.S It is possible with the help of Fetch but I cannot implement this method.

reviews.phtml

<script type="text/javascript">
require([
    "jquery",
    "mage/mage"
],function($) {
    $(document).ready(function() {
        $('#review_form').mage(
            'validation',
            {
                submitHandler: function(form) {
                    var customurl = "<?php echo $this->getUrl().'reviews/index/save'?>";
                    $.ajax({
                        url: customurl,
                        data: $('#review_form').serialize(),
                        type: 'POST',
                        dataType: 'json',
                        showLoader: true,
                        cache: false,
                        success: function(data, status, xhr) {
                            return fetch(customurl)
                            .then( response => {})
                            },
                            $("#review_form").trigger('reset');
                        },
                        error: function (xhr, status, errorThrown) {
                            console.log('Error happens. Try again.');
                            console.log(errorThrown);
                        }
                    });
                }
            }
        );
    });
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.