2

Is there a way to make it work an ajax request with header X-XSRF-TOKEN?

$.ajax({
    type: "POST",
    headers: { 'X-XSRF-TOKEN': token },
    url: '/edit_preset_filters',
    data: data,
    success: function (result) {
        $('#errorSaveFilter').hide();
        $('#save-filters').dialog('close');

    }
});

Error message

message "CSRF token mismatch." exception "Symfony\Component\HttpKernel\Exception\HttpException"

This way I get the token

<?php
$encrypter = app('Illuminate\Encryption\Encrypter');
$encrypted_token = $encrypter->encrypt(csrf_token());
<input id="token" type="hidden" value="{{$encrypted_token}}">
0

1 Answer 1

0

No need to add additional lines for csrf token just add this line,

{{ csrf_field() }}

And in ajax call

var token =  $('input[name="token"]').val(); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.