P
P
Pavel2019-12-24 16:19:45
Laravel
Pavel, 2019-12-24 16:19:45

How to solve 419 error with laravel token?

All with the upcoming!
Help solve the problem with the token!
Here is the code:

<input class="qty-input" type="text" name="testid" value="1" id="count">
<div class="g-input"><input class="" type="text" name="test1" placeholder="Ваш email"></div>
<div class="g-input"><input type="text" name="test2" placeholder="+7 (900) 000-00-00"></div>
<div class="g-input"><textarea maxlength="500" name="message" placeholder="Оставьте комментарий к заказу или задайте интересующий вопрос" id="messagetest"></textarea></div>
<button id="sendOrdertest">Подтвердить отправку</button>

<script type="text/javascript">
    $(document).ready(function() {

        $('#sendOrdertest').click(function(){
            var counttest = $('#testid').val();
            var test1 = $('input[name="test1"]').val();
            var test2 = $('input[name="test2"]').val();
            var messagetest = $('#messagetest').val();
            $.post('{{route('modal.izgotovleniye')}}', {counttest:counttest, test1:test1, test2:test2, messagetest:messagetest}, function(data){
                alert('Тест сработал!')
            });
        });

    });
</script>

route
Route::post('/modal/izgotovleniye/', '[email protected]')->name('modal.izgotovleniye');

controller:
public function modal(request $request){

        Orders::insert(['tel' => $request->test1, 'email' => $request->test2, 'created_at' => date('Y-m-d H:i:s')]);
        
    }

I don’t understand where to insert this token ... I put it in the meta
<meta name="csrf-token" content="{{ csrf_token() }}">
I tried to put in the script
var data = {"_token": $('meta[name="csrf-token"]').attr('content')};
But something didn't go according to plan, it didn't work.
Error 419 has not disappeared

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question