Laravel 5 Ajax with CSRF token

simple, just add the csrf token to your Ajax request.

$_token = "{{ csrf_token() }}";
$.ajax({
url: 'myurl',
type: 'POST',
dataType: 'html',
data: {_token: $_token },
})
.done(function() {
console.log("success");
})
.fail(function() {
console.log("error");
})
.always(function() {
console.log("complete");
});
Advertisements