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 Djerbouh
  • 10,719
  • 6
  • 29
  • 61
Christian
  • 481
  • 1
  • 7
  • 24

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
  • 1,040
  • 1
  • 7
  • 17