ThinkingMan
5 months ago
970
4
Spark

tokenmismatchexception with script

Posted 5 months ago by ThinkingMan

I have read many threads and tested all that I could but am now at the end of my rope. Tried resetting cookies, clearing cache, setting CSRF on the views, looked at the configs and just cannot figure out why I am getting a mismatch when running the script below. I thought that maybe it had to do with the session storage path since I am using Spark but that seems to be correct (app\storage\framework\sessions). Just lost!

@section('script')
    <script>
        $(function() {
            $('#mr-test-connection').on('click' , function () {
                var connection_btn = $(this);
                connection_btn.children('span').removeClass('hide');
                connection_btn.children('span').addClass('fa-spin');
                connection_btn.attr('disabled' , 'disabled');

                var van = $('#pos_wan_address');
                ip = van.val();
                db_name = $('#db_name').val();
                pos_mysql_un = $('#pos_mysql_un').val();
                pos_mysql_pw = $('#pos_mysql_pw').val();
                data = {'pos_wan_address' : ip , 'pos_mysql_un': pos_mysql_un , 'pos_mysql_pw':pos_mysql_pw , 'db_name':db_name};

                $.ajax({
                    url: "{!! route('admin.merchants.test-connection') !!}",
                    data: data,
                    headers: { 'X-XSRF-TOKEN' : '{{\Illuminate\Support\Facades\Crypt::encrypt(csrf_token())}}' },
                    error: function() {

                    },
                    success: function(data) {

                        connection_btn.children('span').addClass('hide');

                        if (data.alert_type)
                            toastr["success"](data.message);
                        else
                            toastr["error"](data.message);

                        connection_btn.removeAttr('disabled');
                    },
                    type: 'POST'
                });

            });

            $('#reset-pass').on('click' , function (e) {

                var reset_email_btn = $(this);

                reset_email_btn.children('span').removeClass('hide');
                reset_email_btn.children('span').addClass('fa-spin');

                merchant_email = "{{$merchant->email}}";
                var action = $(this).attr('data-url');
                $.ajax({
                    url: action,
                    data: {'email': merchant_email},
                    success: function(data) {
                        reset_email_btn.children('span').addClass('hide');
                        reset_email_btn.children('span').removeClass('fa-spin');
                        if (data.alert_type == 'success')
                            toastr.success(data.message , 'Message');
                        else
                            toastr.error(data.message , 'Message');

                    },
                    type: 'get'
                });
            })
        });

    </script>

@endsection()

Please sign in or create an account to participate in this conversation.