Like in the headline mentioned I get a token Mismatch Exception if I try to do ajax
request.
The strange this is, I do have the csrf_token
in my code.
In my <head> ... </head>
i have added this line: <meta name="csrf-token" content="{{ csrf_token() }}">
And above the ajax code I've got this code:
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
But I also tried to put the code into my ajax code. Like this:
$.ajax({
type: "post",
url: "/sendAnswer",
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
data: {'question': question, 'answer': answer},
success: function (data) {
},
error: function (data) {
}
});
And I also tried this:
$.ajax({
type: "post",
url: "/sendAnswer",
data: {'_token': "{{ csrf_token() }}", 'question': question, 'answer': answer},
success: function (data) {
},
error: function (data) {
}
});
Now everything I've tried, gave me a Token Mismatch Exception back.
The Javascript code you see is at the very bottom of my page.