CRSF Token mismatch error Hello, I'am making a Single Page Application, after Two Ajax Requests I have this error " TokenMismatchException in VerifyCsrfToken.php line 67 ". How can I avoid that ? I notice that I'am starting with laravel 5.2. Thank you!
This is what i use
// CSRF protection
$.ajaxSetup({
headers:
{
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
}
});
ok This is what i use too with angularjs :
$scope.update = function(){
$scope.loading = true;
$scope.record._token = $('input[name=_token]').val();
$http.put('/api/category/'+$scope.record.id,
$scope.record,
{'X-CSRF-Token': $('meta[name=_token]').attr('content')}
).success(function(d) {
$scope.loading = false;
if(d.success){
// window.location.href=d.url;
//$scope.init();
}else{
// $scope.operation = d;
}
}).error(function(e){
$scope.loading = false;
console.log(e);
//$scope.operation = e;
});
};
is it correct ?
Ok I saw my mistake, an a correct like this :
In blade
App title ...
In the form view :
Libellé
Description
Enregistrer
{{ csrf_field() }}
In Ajax Script :
$scope.update = function(){
$scope.loading = true;
$scope.record._token = $('input[name=_token]').val();
$http.put('/api/category/'+$scope.record.id,
$scope.record,
{'X-CSRF-Token': $('meta[name=csrf-token]').attr('content')}
).success(function(d) {
$scope.loading = false;
if(d.success){
//window.location.href=d.url;
//$scope.init();
}else{
// $scope.operation = d;
}
}).error(function(e){
$scope.loading = false;
console.log(e);
//$scope.operation = e;
});
};
Now All is OK thank you very m atch!
Please sign in or create an account to participate in this conversation.