2

I added ajax login form in my custom theme and it's working fine in chrome but in Mozilla when I try to log in it redirects me to the same page. I am unable to log in.

Here is my ajax code:

<script>
    require([
        'jquery',
        'mage/mage'
    ], function ($) {
        var dataForm = $('#form-login');
        dataForm.mage('validation', {});

        $('.action-login').on('click',function () {
            if(dataForm.validation('isValid')){
                var formData = new FormData();
                formData.append('username', $('#form-login input[name="username"]').val());
                formData.append('password', $('#form-login input[name="password"]').val());
                $.ajax({
                    url: '<?php echo $block->getAjaxLoginUrl(); ?>',
                    data: formData,
                    processData: false,
                    contentType: false,
                    showLoader: true,
                    type: 'POST',
                    dataType: 'json',
                    success: function (response) {
                        console.log(response);
                        if (!response.errors) {
                            location.reload();
                        } else {
                            $('.popup-login .form-login .messages .message div').text(response.message);
                            $('.popup-login .form-login .messages .message').show();
                            setTimeout(function() {
                                $('.popup-login .form-login .messages .message').hide();
                            }, 5000);
                        }
                    }
                });
                return false;
            }
        })
    });
</script>

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.