Form in Laravel that is interactive with Javascript - Works fine until I submit.
I got this error:
error 419 session expired.
So I add @csrf in my form and Javascript doesn't work.
I want my Javascript form works in Laravel
I try this:
<meta name="csrf-token" content="{{ csrf_token() }}">
And this at the end of body tag(put in script tag):
var xhttp = new XMLHttpRequest();
xhttp.open("POST", url , true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.setRequestHeader("X-CSRF-TOKEN", document.head.querySelector("[name=csrf-token]").content );
xhttp.send(params);
Also try other things. nothing seems to work. I am really frustrated.