Ive tried to send the _token value both in the header and within the send() brackets, but nothing seems to be working. How do I send the token so that Laravel will pick it up correctly?
Have you checked that the input "_token" gets to the server?
I have only done it with jQuery, and the code was something like this:
// Get the token value from the hidden form
token = $('input[name="_token"]').val();
// Send the ajax request
$.ajax({
method: "POST"
url: '/request/url',
data: {_token: token, other_param: value}
});
(I'm writing off memory, so the code might not be 100% correct)
Figured it out. I needed to set content type in the request header
var token = document.getElementsByTagName('input').item(name="_token").value;
var data = "_token="+token;
xmlhttp.open("POST", "ajax/myFunction", true);
xmlhttp.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send(data);
Thanks for the suggestions. They pointed me in the right direction.