lundi 12 septembre 2016

TokenMismatchException in VerifyCsrfToken in Laravel 5.1 + angular

I have Laravel 5.1 + angular form sending JSON request when user want to send mail from website feedback form.

I did my form according to documentation here http://ift.tt/2cmWmgK and anyway I get error message TokenMismatchException in VerifyCsrfToken.php line 53:

I found a lot of topics on stackoverflow, but no real solution. Is there?

in header of my layout I have

<meta name="csrf-token" content="{!! csrf_token() !!}">
<script>
    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });
</script>

then in my form I have this

        <form name="callback" ng-controller="callbackController" role="form" class="" enctype="multipart/form-data">
          {!! csrf_field() !!}
    ...
    ...
<button type="submit" class="btn btn-primary pull-right" ng-click="submit(callback.$valid)" ng-bind="submittext" ng-class="{ 'btn-danger': callback.name.$touched && callback.name.$invalid || callback.tel.$touched && callback.tel.$invalid, 'btn-success': callback.name.$touched && callback.name.$valid && callback.tel.$touched && callback.tel.$valid, }">Send</button>

    </form>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire