@sebastian.virlan it makes more sense to use a GET request since you're retrieving data.
Jun 11, 2016
8
Level 1
TokenMismatchException RANDOM via ajax requests only on Chrome Windows
How this can be explained?
- Clean install Laravel
- Using redis for session and cache
- The problem occur only if I start the server on windows and only shows on Chrome.
- Using a simple js function for ajax call:
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
data: {
_token: $('meta[name="csrf-token"]').attr('content')
}
});
for(var i = 0; i < 5; i++){
getUsers();
}
function getUsers() {
$.ajax({
url: '/users',
type: 'POST',
success: function(data) {
console.log(data);
}
});
}
- Setting CSRF in meta
<meta name="csrf-token" content="{{ csrf_token() }}" /> - Returning a JSON with data:
public function users() {
$users = User::all();
return response()->json([
'users' => $users,
]);
}
- At the final of the video you can see RANDOM TokenMismatchException even the token never change but sometime error occur.
https://www.youtube.com/watch?v=QDucHoP647g
I know this problem has been discussed from years but why does not exist a solution for this?
Please or to participate in this conversation.
