0

I Want Register user with modal And Rapid Authentication,I'm Using Ajax for sent data. My Code is here:

 <div class="modal fade" tabindex="-1" role="dialog" id="mySignup">
    <div class="modal-dialog" role="document">
        <div class="login-wrap">
            <div class="form text-center">
                <input type="text" name="name" id="name"/>
                <input type="email"  name="email" id="email"/>
                <input type="password" name="pw" id="password"/>
                <button id="SignUp">Signup</button>
            </div>
        </div>
        {{csrf_field()}}
    </div>
</div>
<script>
$(document).ready(function () {
    $('#SignUp').click(function (event) {
        var name = $('#name').val();
        var email = $('#email').val();
        var password =$('#password').val();
        $.post('/register',{
            'name' : name,
            'email' :email,
            'password':password,
            'token':$('input[name=_token]').val()
        });
    });
});
</script>

And In Web.php I'm Using this code:

Route::post('/register',[
'as'=> '',
'uses' => 'Auth\RegisterController@Register'
 ]);

But When I Want SignUp I give this Error message with 419 status code {message: "", exception: "Symfony\Component\HttpKernel\Exception\HttpException",…} How I Can fix this problem?

2 Answers 2

1

change token to _token as laravel checks CSRF token in _token

'_token':$('input[name=_token]').val()
Sign up to request clarification or add additional context in comments.

1 Comment

oh!Yes Tanks a lot
0

You need to pass token in header

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

Add header on ajax call

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.