Answer the question
In order to leave comments, you need to log in
Why is the 419 error coming?
Hello! I am doing authorization on the project and faced the fact that when sending data, the server returns 419.
Here is my html code:
<div class="modal-dialog">
<div class="modal-header">
<h2>Авторизация </h2>
<label class="btn-close" for="modal-1" aria-hidden="true">×</label>
</div>
<div class="modal-body">
<input id="email" type="text" class="modal-body__text" placeholder="Email" required>
<input id="password" type="password" class="modal-body__text" placeholder="Password" required>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" onclick="auth();">Войти</button>
</div>
</div>
function auth(){
var email = document.getElementById('email').value;
var password = document.getElementById('password').value;
var tokenHeader = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
var postdata = new Headers({
'Content-Type': 'application/json',
'X-CSRF-TOKEN': tokenHeader
});
var url = '{!!route('login')!!}';
fetch(url,{
method: 'POST',
postdata,
body: JSON.stringify({email: email, password:password, _token: '{!!csrf_token()!!}'})
}).then((response)=>{
return response.json();
}).then((data)=>{
console.log(data)
}).catch((error)=>{
console.log(error)
});
}
Answer the question
In order to leave comments, you need to log in
Are you sure you added a hidden field to the markup @csrf
? The token must be sent in the Request body for each type of request (GET exception).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question