0

enter image description here

Hii My website is not working on other server code is same into both server

1, Working server

http://programmingly.com/articles/

  • testuser@gmail.com
  • 12345678 (Working perfect)

https://www.vennocracy.com/

  • testuser@gmail.com
  • 12345678 (Not Working)

I tried ajax for that

$('#login-form').validate({
        rules: {
            email: {
                required: true,
            },
            password: {
                required: true,
            },
        },
        messages: {
            email: {
                required: 'Please enter email',
            },
            password: {
                required: 'Please enter password',
            },
        },
        submitHandler: function(form) {
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                url: "{{ route('user.ajaxlogin') }}",
                type: "POST",
                data: new FormData(form),
                dataType: 'json',
                contentType: false,
                cache: false,
                processData: false,
                beforeSend: function() {
                    $("body").append(
                        "<div class='ajax-overlay'><i class='porto-loading-icon'></i></div>"
                        );
                },
                success: function(res) {
                    $(".ajax-overlay").remove();
                    if (res.status) {
                        $('.all-error').html('');
                        $('.all-success').html('');
                        $('.all-success').html(res.message);
                        setTimeout(function() {
                            $("#loginModal").modal('hide');
                            location.reload();
                        }, 4000);
                    } else {
                        $('.all-error').html('');
                        $('.all-error').html(res.message);
                    }
                },
                error: function(data) {
                    $(".ajax-overlay").remove();
                    var errorString = '';
                    $.each(data.responseJSON.errors, function(key, value) {
                        errorString += value + '<br>';
                    });
                    $('.all-error').html('');
                    $('.all-success').html('');
                    $('.all-error').html(errorString);
                },
            });
            return false;
        }
    });
Ravi Makwana
  • 375
  • 1
  • 4
  • 12
  • clear cache also make sure you have the correct domain set in your ``.env`` file. – OMi Shah Nov 10 '22 at 16:43
  • Does this answer your question? [Laravel 5.4 Token Mismatch Exception on live server](https://stackoverflow.com/questions/46279779/laravel-5-4-token-mismatch-exception-on-live-server) – OMi Shah Nov 10 '22 at 16:46
  • Also, duplicate of https://stackoverflow.com/questions/62967224/how-to-solve-csrf-token-mismatch-in-laravel – OMi Shah Nov 10 '22 at 16:47
  • @OMiShah Domain Setup correctly – Ravi Makwana Nov 10 '22 at 16:48
  • 1
    there are no cookies being set in the 2nd domain. Perhaps the session is not properly configured – apokryfos Nov 10 '22 at 16:56
  • How can i set cookies and session as per your say – Ravi Makwana Nov 10 '22 at 16:57
  • Setting cookies and starting the session is done by middleware (e.g. in [Kernel.php](https://github.com/laravel/laravel/blob/9.x/app/Http/Kernel.php) `AddQueuedCookiesToResponse` and `StartSession`) since the code in both domains is the same then presumably this code is still in there but since cookies are not set it probably means that `StartSession` does not work and does not add any cookie to the response, which probably means a session configuration issue – apokryfos Nov 11 '22 at 07:05

1 Answers1

0

I had the same problem when moving a laravel project to another server. Then I start using csrf token globally. It work perfectly.

Add this meta tag to your HTML code between the head tags.

    <meta name="csrf-token" content="{{ csrf_token() }}">

Add this AXAJ setup to the one of your scripts at the top.

    $.ajaxSetup({
headers: {
    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}});

then you don't have to call the csrf token into your all javascript functions. Let me know if it's fix your issue.