angularjs - TokenMismatchException in VerifyCsrfToken in Laravel 5.1 + angular -


i have laravel 5.1 + angular form sending json request when user want send mail website feedback form.

i did form according documentation here https://laravel.com/docs/master/csrf , anyway error message tokenmismatchexception in verifycsrftoken.php line 53:

i found lot of topics on stackoverflow, no real solution. there?

in header of layout have

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

then in form 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> 

here code of angular

angular.module('myapp', ['ngmessages', 'angularfileupload'])    .controller('callbackcontroller', function($scope, $http, $timeout) {      $scope.formdata = {};     $scope.url = '/';     $scope.submittext = 'Отправить';      $scope.submit = function(isvalid) {       if (isvalid) {           $scope.submittext = 'Отправляем...';           $http.post($scope.url,              {               "formname": "callback",                "name": $scope.name,                "tel": $scope.tel,                "time": $scope.time,                "email": $scope.email,                "msg": $scope.msg             }).                         success(function(data, status) {                             console.log(data);                             $scope.status = status;                             $scope.data = data;                             $scope.result = data;                         });               $timeout(function() {                   $('#callback').modal('hide');                 $scope.submittext = 'Отправить';                 $scope.name = null;                 $scope.tel = null;                 $scope.time = null;                 $scope.email = null;                 $scope.msg = null;                 $scope.callback.$setpristine();                 $scope.callback.$setuntouched();               },    1000);        } else {               $('.errors').modal('show');             }          }    }) 

the problem code second line in form

{!! csrf_field() !!} 

generates code like:

<input type="hidden" name="_token" value="zwiqq3bjfbwmr4goixtcklwgvpxien8vkwninhil"> 

which not need.

just link have posted, need put following line in head area:

<meta name="csrf-token" content="{{ csrf_token() }}"> 

because using ajax, adding header picks value looking meta tag has name csrf-token


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -