Reputation: 1500
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?
Upvotes: 0
Views: 1512
Reputation: 34914
change token
to _token
as laravel checks CSRF token in _token
'_token':$('input[name=_token]').val()
Upvotes: 1
Reputation: 2111
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')
}
Upvotes: 0