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}}">
Salim
  • 9,886
  • 5
  • 23
  • 55
Christian
  • 465
  • 6
  • 21

1 Answers1

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(); 
Maulik Shah
  • 969
  • 1
  • 6
  • 16