Answer the question
In order to leave comments, you need to log in
What causes the 419 (unknown status) error?
I send a post request through ajax, as a result, an error 419 . (if get request then no errors)
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
url: "/exit",
type: "POST",
data: "get=on",
success: function (response) {
console.log('+')
}
});
<meta name="csrf-token" content="{{ csrf_token() }}">
Answer the question
In order to leave comments, you need to log in
Solved the problem by passing the token to data
$.ajax({
url: "/exit",
type: "POST",
data: {"_token": $('meta[name="csrf-token"]').attr('content')},
success: function (response) {
console.log('+')
}
});
I have a working scheme, without form it looks like this, without going into details, like this:
HTML:
<div>
@csrf{{--эта конструкция преобразуется в input c именем _token, пример: <input type="hidden" name="_token" value="tyiV5lsNJy9aA245dke7979aW1otyutV5D">--}}
<input class='text' type='text'>
<input type='submit'>
</div>
let someV = $('.text').val();
let token = $("input[name='_token']").val();
$.ajax({
type: 'POST',
url: '/someurl',
data: {
'_token': token,
"someV" : someV
},
success:function (res){
console.log('F**k yeah');
}
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question