I would really appreciate some help with this. I tried tons of solutions as posted in this forum, but I cannot get it to work

My ajax call is something like

        $('#ref').blur(function(){
    var ref = $('#ref').val();
    var _token = $("input[name='_token']").val();
    $.ajax({
    url:"{{route('refcheck')}}",
       method: "POST",
       date: {ref:ref, _token,_token},
       success:function (result) {
           if (result==0){
            $('.referror').html('<label class="text-danger"><i class="fa fa-exclamation-circle"></i> Invalid Sposor Id</label>');
                $('.referror').slideDown();
                $('#ref').addClass('has-error');
        }
    }
    })
    });

In Route

    Route::post('/login/refcheck', '[email protected]')->name('refcheck');

And controller

    function refCheck(Request $request){
        return 0;
    }

My login.blade.php is

        <form class="form-contact-warp form-calc-ship cb-form" method="POST" action="{{ route('register') }}">
                 @csrf
    <input id="ref" class="form-control{{ $errors->has('ref') ? ' is-invalid' : '' }}" placeholder="Sponsor" type="text" name="ref" value="@if (request()->has('ref'))
{{request()->ref}}
@elseif(request()->has('ref')=='')
admin
@endif" required autocomplete="name" autofocus>
<div class="errordiv referror"></div>

I am getting this error

POST http://localhost/metazone/public/login/refcheck 419 (unknown status)

2 Answers

1
kerdouchi mohamed On Best Solutions

date: {ref:ref, _token:_token},

0
Michael Nguyen On

you have several typos. Try below

data: {ref:ref, _token:_token},

If it still give 419, do console.log(_token) to make sure your csrf token is valid